{"id":507,"date":"2020-04-08T14:19:15","date_gmt":"2020-04-08T06:19:15","guid":{"rendered":"http:\/\/124.244.86.40:8080\/wordpress\/?p=507"},"modified":"2020-04-08T14:19:15","modified_gmt":"2020-04-08T06:19:15","slug":"golang-header-%e4%b8%ad%e7%9a%84-utf-8-%e6%aa%94%e5%90%8d","status":"publish","type":"post","link":"https:\/\/imuslab.com\/wordpress\/2020\/04\/08\/golang-header-%e4%b8%ad%e7%9a%84-utf-8-%e6%aa%94%e5%90%8d\/","title":{"rendered":"Golang Header \u4e2d\u7684 UTF-8 \u6a94\u540d"},"content":{"rendered":"\n<p>\u4e00\u822c\u4f86\u8aaa\u5982\u679c\u4f60\u60f3\u8b93 Golang \u53bb Serve \u4e00\u500b File \u4f60\u6703\u5728\u6a94\u982d\u52a0\u5165\u4ee5\u4e0b\u5169\u884c\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>w.Header().Set(\"Content-Disposition\", \"attachment; filename=\" + filepath.Base(realFilepath))\nw.Header().Set(\"Content-Type\", r.Header.Get(\"Content-Type\"))<\/code><\/pre>\n\n\n\n<p>\u9019\u6a23\u700f\u89bd\u5668\u5c31\u4e0d\u6703\u64ad\u653e\u591a\u5a92\u9ad4\u6a94\u6848\u800c\u662f\u8f49\u70ba\u4e0b\u8f09\u6a21\u5f0f\u3002\u7136\u800c\uff0c\u5c0d\u65bc\u4e00\u4e9b\u542b\u6709\u7279\u5225\u5b57\u5143 \/ \u7a7a\u683c\u7684\u6a94\u6848\u540d\u7a31\uff0c\u4e00\u822c\u700f\u89bd\u5668\u4e26\u7121\u6cd5\u5b8c\u6574\u8b80\u53d6\u6574\u500b\u6a94\u540d\uff0c\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Ch\u014dcho - Authentic Symphony (Acoustic ver.).mp4\n\/\/\u6a94\u6848\u540d\u7a31\u4e0b\u8f09\u6642\u56e0\u70ba\u7a7a\u683c\u6703\u88ab Firefox \u8b80\u53d6\u6210\nCh\u014dcho<\/code><\/pre>\n\n\n\n<p>\u800c\u5982\u679c\u8981\u89e3\u6c7a\u9019\u500b\u554f\u984c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 Golang \u7684  url.QueryEscape( ) \u529f\u80fd\uff0c\u628a\u6a94\u6848\u540d\u7a31\u5148\u8f49\u63db\u70ba URL Safe \u7684\u540d\u7a31\uff0c\u4f46\u662f\u9019\u6703\u51fa\u73fe\u53e6\u4e00\u500b\u554f\u984c\uff0c\u4f8b\u5982\u4e0a\u9762\u7684\u4f8b\u5b50\u7d93\u904e  QueryEscape  \u4e4b\u5f8c\u6703\u8b8a\u6210\u9019\u6a23<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Ch\u014dcho+-+Authentic+Symphony+(Acoustic+ver.).mp4<\/code><\/pre>\n\n\n\n<p>\u9019\u662f\u56e0\u70ba\u96d6\u7136\u6a19\u6e96\u88e1\u9762\u6709\u5beb\u5230<a href=\"https:\/\/github.com\/golang\/go\/issues\/4013\"> URL Encode + \u8ddf &#8221; &#8220;\uff08\u7a7a\u683c\uff09\u662f\u76f8\u7b49\u7684<\/a>\uff0c\u4f46\u662f\u5f88\u591a\u4e3b\u6d41\u700f\u89bd\u5668\u5c0d URL Encode \u7684\u89e3\u8b80\u53ea\u6709 %20 \u800c\u5df2\uff0c\u6240\u4ee5\u8981\u89e3\u6c7a\u9019\u554f\u984c\u4f60\u5c31\u53ea\u80fd\u5920\u518d\u628a + \u66ff\u63db\u6210 %20 \uff0c\u5b8c\u6574\u7684\u4ee3\u78bc\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>w.Header().Set(\"Content-Disposition\", \"attachment; filename*=UTF-8''\" + strings.ReplaceAll(url.QueryEscape(filepath.Base(realFilepath)),\"+\",\"%20\"))\nw.Header().Set(\"Content-Type\", r.Header.Get(\"Content-Type\"))<\/code><\/pre>\n\n\n\n<p>\u90a3\u4f60\u53ef\u80fd\u6703\u8aaa\u4f60\u7684 + \u865f\u4e0d\u5c31\u662f\u4e0d\u898b\u4e86\u55ce\uff1f\u55ef\uff0c\u6c92\u932f\uff0c\u53ef\u662f\u4f60\u6709\u66f4\u597d\u7684\u89e3\u6c7a\u65b9\u6cd5\u55ce\uff1f<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e00\u822c\u4f86\u8aaa\u5982\u679c\u4f60\u60f3\u8b93 Golang \u53bb Serve \u4e00\u500b File \u4f60\u6703\u5728\u6a94\u982d\u52a0\u5165\u4ee5\u4e0b\u5169\u884c\uff1a \u9019\u6a23\u700f\u89bd\u5668\u5c31\u4e0d\u6703\u64ad\u653e\u591a\u5a92\u9ad4\u6a94\u6848\u800c\u662f\u8f49\u70ba\u4e0b\u8f09\u6a21\u5f0f\u3002\u7136\u800c\uff0c\u5c0d\u65bc\u4e00\u4e9b\u542b\u6709\u7279\u5225\u5b57\u5143 \/ \u7a7a\u683c\u7684\u6a94\u6848\u540d\u7a31\uff0c\u4e00\u822c\u700f\u89bd\u5668\u4e26\u7121\u6cd5\u5b8c\u6574\u8b80\u53d6\u6574\u500b\u6a94\u540d\uff0c\u4f8b\u5982\uff1a \u800c\u5982\u679c\u8981\u89e3\u6c7a\u9019\u500b\u554f\u984c\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528 Golang \u7684 url.QueryEscape( ) \u529f\u80fd\uff0c\u628a\u6a94\u6848\u540d\u7a31\u5148\u8f49\u63db\u70ba URL Safe \u7684\u540d\u7a31\uff0c\u4f46\u662f\u9019\u6703\u51fa\u73fe\u53e6\u4e00\u500b\u554f\u984c\uff0c\u4f8b\u5982\u4e0a\u9762\u7684\u4f8b\u5b50\u7d93\u904e QueryEscape \u4e4b\u5f8c\u6703\u8b8a\u6210\u9019\u6a23 \u9019\u662f\u56e0\u70ba\u96d6\u7136\u6a19\u6e96\u88e1\u9762\u6709\u5beb\u5230 URL Encode + \u8ddf &#8221; &#8220;\uff08\u7a7a\u683c\uff09\u662f\u76f8\u7b49\u7684\uff0c\u4f46\u662f\u5f88\u591a\u4e3b\u6d41\u700f\u89bd\u5668\u5c0d URL Encode \u7684\u89e3\u8b80\u53ea\u6709 %20 \u800c\u5df2\uff0c\u6240\u4ee5\u8981\u89e3\u6c7a\u9019\u554f\u984c\u4f60\u5c31\u53ea\u80fd\u5920\u518d\u628a + \u66ff\u63db\u6210 %20 \uff0c\u5b8c\u6574\u7684\u4ee3\u78bc\u5982\u4e0b\uff1a \u90a3\u4f60\u53ef\u80fd\u6703\u8aaa\u4f60\u7684 + \u865f\u4e0d\u5c31\u662f\u4e0d\u898b\u4e86\u55ce\uff1f\u55ef\uff0c\u6c92\u932f\uff0c\u53ef\u662f\u4f60\u6709\u66f4\u597d\u7684\u89e3\u6c7a\u65b9\u6cd5\u55ce\uff1f<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3],"tags":[89,96,97,98],"class_list":["post-507","post","type-post","status-publish","format-standard","hentry","category-instructions-and-information","tag-golang","tag-header","tag-queryescape","tag-space"],"_links":{"self":[{"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/posts\/507","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/comments?post=507"}],"version-history":[{"count":1,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/posts\/507\/revisions"}],"predecessor-version":[{"id":508,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/posts\/507\/revisions\/508"}],"wp:attachment":[{"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/media?parent=507"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/categories?post=507"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/imuslab.com\/wordpress\/wp-json\/wp\/v2\/tags?post=507"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}