{"id":92705,"date":"2020-03-17T16:26:20","date_gmt":"2020-03-17T08:26:20","guid":{"rendered":"http:\/\/4563.org\/?p=92705"},"modified":"2020-03-17T16:26:20","modified_gmt":"2020-03-17T08:26:20","slug":"go-%e4%bb%a3%e7%90%86%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=92705","title":{"rendered":"go \u4ee3\u7406\u95ee\u9898"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  go \u4ee3\u7406\u95ee\u9898               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : 347443579 <\/span>  <span><i><\/i> 24<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<pre><code>const proxyServer = \"http-dyn.abuyun.com:9020\"  \/\/ \u4ee3\u7406\u96a7\u9053\u9a8c\u8bc1\u4fe1\u606f const proxyUser  = \"H8K54D3646J2X67D\"; const proxyPass  = \"C6228A18B130EF63\";  type AbuyunProxy struct {  AppID string  AppSecret string }  func (p AbuyunProxy) ProxyClient() http.Client {  proxyUrl, _ := url.Parse(\"http:\/\/\"+ p.AppID +\":\"+ p.AppSecret +\"@\"+ proxyServer)  return http.Client{Transport: &amp;http.Transport{Proxy: http.ProxyURL(proxyUrl)}} } func main()  {  targetUrl := \"https:\/\/anime-pictures.net\/pictures\/download_image\/640247-5528x3508-kimetsu+no+yaiba-uzui+tengen-mikki-single-short+hair-highres.png\"  \/\/ \u521d\u59cb\u5316 proxy http client  client := AbuyunProxy{AppID: proxyUser, AppSecret: proxyPass}.ProxyClient()   request, _ := http.NewRequest(\"GET\", targetUrl, bytes.NewBuffer([]byte(``)))   response, err := client.Do(request)   if err != nil {   panic(\"failed to connect: \" + err.Error())  }  \/*response, err := http.Get(targetUrl)  if err != nil{   fmt.Println(\"\u8bf7\u6c42\u56fe\u7247 url \u5931\u8d25\",err)  }*\/  fmt.Println(response)  defer response.Body.Close()  name := \".\/H_1.jpg\"  out, err := os.Create(name)  if err != nil{   fmt.Println(\"\u521b\u5efa\u6587\u4ef6\u5931\u8d25\",err)  }  defer out.Close()  pix, err := ioutil.ReadAll(response.Body)  if err != nil{   fmt.Println(err)  }  _, err = io.Copy(out, bytes.NewReader(pix))  if err != nil {   fmt.Println(\"\u4e0b\u8f7d\u6587\u4ef6\u5931\u8d25\",err)  } } <\/code><\/pre>\n<p>\u5404\u4f4d\u5927\u4f6c\u5e2e\u5fd9\u770b\u4e00\u4e0b\uff0c\u6211\u7528\u4ee3\u7406\u8fd4\u56de\u7684 status \u662f 200\uff0c\u4f46\u662f ioutil.ReadAll \u8bfb\u53d6\u4f1a\u51fa\u73b0 unexpected EOF \u9519\u8bef\uff0c\u540e\u9762\u6211\u53c8\u7528\u4e86\u4e0a\u9762\u6ce8\u91ca\u7684 http.Get \u8bf7\u6c42\uff0cioutil.ReadAll \u8bfb\u53d6\u662f\u53ef\u4ee5\u4fdd\u5b58\u56fe\u7247\u7684\uff0c\u4f46\u662f http.Get \u8bf7\u6c42\u548c\u4ee3\u7406\u8bf7\u6c42\u90fd\u662f status\uff0c\u4e3a\u4ec0\u4e48\u4ee3\u7406\u4e0d\u80fd\u88ab ioutil.ReadAll \u8bfb\u53d6\u5462\uff0c\u4e0a\u9762\u4ee3\u7406\u7528\u7684\u662f\u963f\u5e03\u4e91\u7684\u4ee3\u7406\uff0c\u6d4b\u8bd5\u8d26\u53f7\u5df2\u7ecf\u662f\u8fc7\u671f\u7684<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>8<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"979036\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Fitz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u51e0\u4e2a\u95ee\u9898<br \/>1. http.Get \u4f1a\u4f7f\u7528 DefaultClient, \u6839\u672c\u5c31\u4e0d\u8d70\u4ee3\u7406, \u4f60\u9700\u8981\u7528 client.Get<br \/>2. err != nil \u4f60\u9700\u8981\u5904\u7406 \u800c\u4e0d\u662f\u6253\u5370\u4e00\u4e0b\u5c31\u7ee7\u7eed\u5f80\u4e0b\u6267\u884c<br \/>3. io.copy \u4e0d\u662f\u76f4\u63a5\u53ef\u4ee5\u628a body \u7684\u6570\u636e\u5199\u5165\u5230 os file \u4e2d\u5417, `_, err = io.Copy(out, response.Body)` \u7ed5\u8fd9\u4e48\u5927\u4e00\u5708\u521b\u5efa pix \u662f\u5e72\u4ec0\u4e48\u5462<br \/>4. &#8220;\u4f46\u662f http.Get \u8bf7\u6c42\u548c\u4ee3\u7406\u8bf7\u6c42\u90fd\u662f status&#8221; \u8fd9\u662f\u4ec0\u4e48\u610f\u601d<br \/>5. err \u90fd\u5904\u7406\u4e0b, \u4e0d\u8981\u7528\u4e0b\u5212\u7ebf\u5ffd\u7565<\/p>\n<p>unexpected EOF \u4e00\u822c\u662f\u5728\u8bfb\u53d6\u56fa\u5b9a\u957f\u5ea6\u7684\u65f6\u5019\u6ca1\u8bfb\u591f\u624d\u4f1a\u51fa\u73b0\u7684, readall \u5e94\u8be5\u4e0d\u4f1a\u51fa\u73b0\u5427, \u4f60\u8fd9\u4e2a\u56fe\u7247\u592a\u5927\u4e86, \u6211\u7528\u672c\u5730\u7684\u4ee3\u7406\u8bd5\u4e86\u4e0b\u5176\u4ed6\u56fe\u7247\u6ca1\u4ec0\u4e48\u95ee\u9898                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"979037\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 347443579 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Fitz \u7b2c\u4e00\u4e2a\u95ee\u9898\uff0c\u6211\u7684\u610f\u601d\u662f\u6ce8\u91ca\u7684\u90a3\u6bb5 http.Get \u53ef\u4ee5\u4fdd\u5b58\u56fe\u7247\uff0c\u7528\u4ee3\u7406\u4e0d\u884c\uff0c\u7b2c\u4e8c\u4e2a\u6253\u5370\u4e00\u4e0b\u7ee7\u7eed\u6267\u884c\uff0c\u56e0\u4e3a\u6211\u505a\u7684\u662f\u722c\u866b\uff0c\u4e0d\u53ef\u80fd\u4e2d\u65ad\uff0c\u91cd\u65b0\u8bb0\u5f55\u8fd9\u6761\u8bb0\u5f55\u592a\u9ebb\u70e6\u4e86\uff0c\u6253\u5370\u9519\u8bef\uff0c\u76f4\u63a5\u629b\u5f03\u5f80\u4e0b\u6267\u884c\uff0c\u7b2c\u4e09\u4e2a\u95ee\u9898\uff0c\u6211\u4e5f\u4e0d\u77e5\u9053\u4e3a\u4ec0\u4e48\u8981\u8bfb\u53d6\uff0c\u6211\u5728\u7f51\u4e0a\u627e\u7684 go \u4e0b\u8f7d\u7f51\u7edc\u56fe\u7247\u90fd\u6709\u8fd9\u4e2a\u6b65\u9aa4\uff0c\u6211 go \u521a\u5b66\u6ca1\u591a\u4e45\uff0c\u4e00\u76f4\u65ad\u65ad\u7eed\u7eed\u7684\uff0c\u53ea\u80fd\u7167\u6284\uff0c\u7b2c\u56db\u4e2a\u6211\u7684\u9519\uff0c\u6ca1\u8bb2\u6e05\u695a\uff0c\u610f\u601d\u662f\u8fd4\u56de\u7684 http \u7684 status \u90fd\u662f 200\uff0c\u4e5f\u5c31\u662f\u6210\u529f\u4e86\uff0c\u8fd4\u56de\u90fd\u6210\u529f\u4e86\uff0c\u4ee3\u7406\u7684 response.Body \u8bfb\u53d6\u4e0d\u4e86\uff0c\u6ce8\u91ca\u7684\u54ea\u4e2a http.Get \u8fd4\u56de\u7684 response.Body \u5374\u80fd\u4fdd\u5b58                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"979038\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Fitz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u5927\u6982\u7387\u662f\u4ee3\u7406\u670d\u52a1\u5668\u6709\u95ee\u9898                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"979039\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ljy1398202806 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Fitz \u521d\u5b66 go\uff0cerr \u90fd\u5904\u7406\u611f\u89c9\u7279\u522b\u9ebb\u70e6\uff0c\u800c\u4e14\u4ee3\u7801\u770b\u7740\u5168\u662f\u5224\u65ad\u9519\u8bef\uff0c\u8fd9\u4e2a\u6709\u5f88\u5927\u7684\u597d\u5904\u4e48\u3002\u3002\u4e00\u4e9b\u81ea\u5df1\u5224\u65ad\u57fa\u672c\u4e0d\u4f1a\u51fa\u9519\u7684\u4ee3\u7801\u53ef\u4e0d\u53ef\u4ee5\u5ffd\u7565\u6389 err                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"979040\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : 347443579 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ljy1398202806 \u5c31 err \u5783\u573e\uff0c\u5176\u4ed6\u7684 go \u5b8c\u7206\u6240\u6709\uff01\uff01                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"979041\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Fitz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @ljy1398202806 \u6ca1\u529e\u6cd5, \u5f53\u521d\u521b\u9020 golang \u7684\u51e0\u4e2a\u4eba\u90fd\u662f unix \u65f6\u4ee3\u7684\u9057\u8001\u9057\u5c11, \u6309\u7167\u5b98\u65b9\u7684\u8bf4\u6cd5\u5c31\u662f&#8221;\u50cf try-cache \u90a3\u6837\u5c06\u5f02\u5e38\u8026\u5408\u5728\u63a7\u5236\u7ed3\u6784\u4e2d\u4f1a\u5bfc\u81f4\u4ee3\u7801\u6df7\u4e71&#8221;.<\/p>\n<p>\u592a\u591a\u91cd\u590d\u7684 err \u5224\u65ad\u4e00\u76f4\u662f go \u5e7f\u53d7\u8bdf\u75c5\u7684\u4e09\u5927\u95ee\u9898\u4e4b\u4e00,\u53e6\u4e24\u4e2a\u662f\u5305\u7ba1\u7406\u548c\u6cdb\u578b,\u800c\u4e14\u81ea\u4ece try \u63d0\u6848\u88ab\u5426\u51b3, \u5173\u4e8e\u9519\u8bef\u5904\u7406\u57fa\u672c\u4e0d\u4f1a\u518d\u6709\u6539\u8fdb\u4e86, \u6309 russ cox \u7684\u8bdd\u5c31\u662f\u518d\u7b49\u4e2a\u5341\u5e74&#8230;..                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"979042\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : Fitz <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8279 \u600e\u5199\u6210 try-cache \u4e86                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"979043\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : ljy1398202806 <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @Fitz \u8c22\u8c22\u5927\u4f6c                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>go \u4ee3\u7406\u95ee\u9898 \u8cc7\u6df1\u5927\u4f6c : 34&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/92705"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=92705"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/92705\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=92705"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=92705"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=92705"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}