{"id":4518,"date":"2017-03-31T17:43:54","date_gmt":"2017-03-31T09:43:54","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=4518"},"modified":"2017-03-31T18:00:39","modified_gmt":"2017-03-31T10:00:39","slug":"thttpclient-post%e6%96%b9%e6%b3%95%e5%ae%98%e6%96%b9bug-%e7%95%99%e6%84%8f","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=4518","title":{"rendered":"\u5b98\u65b9THTTPClient.Post\u65b9\u6cd5\u3010\u4f4e\u7ea7\u3001\u4e25\u91cd\u3011bug &#8212; \u9700\u7559\u610f"},"content":{"rendered":"<h3><span style=\"color: #ff0000\"><strong>\u6211\u4e00\u76f4\u90fd\u5728\u5bfb\u627e\u5404\u79cd\u4e1a\u52a1\u529f\u80fd\u7684\u6700\u7b80\u5355\u5199\u6cd5\uff0c\u7528\u51cf\u6cd5\u7684\u6a21\u5f0f\u6765\u5f00\u53d1\u8f6f\u4ef6\u3002\u5982\u679c\u6709\u6bd4\u6211\u7684\u5199\u6cd5\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\uff0c\u8bf7\u7559\u8a00\u544a\u77e5\u3002<\/strong><\/span><\/h3>\n<h4>\u4e8b\u60c5\u7ecf\u8fc7\uff1a<\/h4>\n<h4>\u4eca\u65e5\u4e0b\u5348\u7528THTTPClient.Post\u65b9\u6cd5 \u63d0\u4ea4\u7684\u65f6\u5019\uff0c\u670d\u52a1\u7aef\u8001\u662f\u81ea\u52a8\u8fc7\u6ee4\u6389\uff0c\u767e\u601d\u4e0d\u5f97\u5176\u89e3\u3002\u82b1\u8d39\u8fd12\u5c0f\u65f6\u8c03\u8bd5 \u68c0\u67e5\u4e86\u5f88\u591a\u904d\u7a0b\u5e8f \u4f9d\u7136\u4e0d\u884c\u3002\u4e8e\u662f\u5c31\u5f00\u59cb\u6000\u7591<\/h4>\n<h4>THttpClient\u7684\u95ee\u9898\uff0c\u6211\u5207\u6362\u6210indy\u7684IdHTTP \u679c\u7136\u53ef\u4ee5\u4e86\uff0c\u90a3\u95ee\u9898\u51fa\u5728\u54ea\u91cc\u5462\uff0c\u4e8e\u662f\u5f00\u59cb \u65ad\u70b9\u5230\u00a0THTTPClient.Post \u65b9\u6cd5\u5185\u90e8\u53bb\u770b\uff0c\u53d1\u73b0\u4e86\u5b98\u65b9\u7684\u4e00\u4e2a\u975e\u5e38<\/h4>\n<h4>\u4f4e\u7ea7\u7684Bug\uff0c<span style=\"color: #0000ff\"><strong>\u8fd9\u4e2abug\u4eceTHttpClient\u88ab\u53d1\u660e\u81f3\u4eca \u4e00\u76f4\u90fd\u8fd8\u5b58\u5728\uff01\uff01\uff01\uff01\u5df2\u8bc1\u660e\uff1adelphi 10\u300110.1\u300110.1.2\u300110.2 \u90fd\u6ca1\u4fee\u590d\uff01\uff01\uff01\uff1b<span style=\"color: #ff00ff\">\u6211\u51b3\u5b9a\u5199\u7bc7\u535a\u5ba2<\/span><\/strong><\/span><\/h4>\n<h4><span style=\"color: #ff00ff\"><strong>\u5e0c\u671b\u80fd\u5e2e\u52a9\u5230\u7f51\u53cb\u4eec\u3002<\/strong><\/span><\/h4>\n<h4>\u5b98\u65b9\u7684\u65b9\u6cd5\u58f0\u660e\uff1a<\/h4>\n<pre class=\"lang:delphi decode:true \">    \/\/\/ &lt;summary&gt;Post TStrings values adding multipart info&lt;\/summary&gt;\r\n    function Post(const AURL: string; const ASource: TStrings; const AResponseContent: TStream = nil;\r\n      const AEncoding: TEncoding = nil; const AHeaders: TNetHeaders = nil): IHTTPResponse; overload;<\/pre>\n<p>&nbsp;<\/p>\n<h4>\u4e0b\u9762\u4ee5\u5b9e\u4f8b\u6765\u8bf4\u660e\uff1a<\/h4>\n<pre class=\"lang:delphi decode:true \">procedure TForm4.Button1Click(Sender: TObject);\r\nvar\r\n  MyList: TStringList;\r\n  MyHTTPClient: THTTPClient;\r\n  MyJson: string;\r\nbegin\r\n  MyList := TStringList.Create;\r\n  MyHTTPClient := THTTPClient.Create;\r\n  try\r\n    MyList.Values['qdac'] := 'https:\/\/blog.qdac.cc';\r\n    MyList.Values['age'] := '4';\r\n\r\n    \/\/\u6ce8\u610f\u7b2c\u56db\u4e2a\u53c2\u6570TEncoding.UTF8\r\n    MyJson := MyHTTPClient.Post('https:\/\/blog.qdac.cc', MyList, nil, TEncoding.UTF8, nil).ContentAsString(TEncoding.UTF8);\r\n    Memo1.Lines.Add(MyJson);\r\n  finally\r\n    MyList.Free;\r\n    MyHTTPClient.Free;\r\n  end;\r\nend;<\/pre>\n<h3>\u5982\u4e0a\u4ee3\u7801\uff0c\u6211\u4eec\u65ad\u70b9\u5230Post\u65b9\u6cd5\u5185\u90e8\u770b\u770b\uff1a<\/h3>\n<p><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ff.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4519 size-full\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ff.jpg\" alt=\"\" width=\"1535\" height=\"881\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ff.jpg 1535w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ff-300x172.jpg 300w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ff-768x441.jpg 768w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ff-1024x588.jpg 1024w\" sizes=\"auto, (max-width: 1535px) 100vw, 1535px\" \/><\/a><\/p>\n<p>&nbsp;<\/p>\n<p><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/gg-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4521 size-full\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/gg-1.jpg\" alt=\"\" width=\"1540\" height=\"883\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/gg-1.jpg 1540w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/gg-1-300x172.jpg 300w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/gg-1-768x440.jpg 768w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/gg-1-1024x587.jpg 1024w\" sizes=\"auto, (max-width: 1540px) 100vw, 1540px\" \/><\/a><\/p>\n<h4><\/h4>\n<h4>\u6211\u4eec\u63a5\u4e0b\u6765\u770b\u770b \u5b98\u65b9\u7684EncodingNameToHttpEncodingName \u8fd9\u4e2a\u65b9\u6cd5\u505a\u4e86\u4ec0\u4e48\uff1a<\/h4>\n<h4>\uff08<span style=\"color: #ff0000\"><strong>\u7b54\u6848\u662f\u5565\u4e5f\u6ca1\u5e72\uff0c\u5b98\u65b9\u5199\u7a0b\u5e8f\u7684\u65f6\u5019\u7a7a\u4e86\u4e00\u884c\uff0c\u7761\u7740\u4e86\uff0c\u5fd8\u8bb0\u5199\u4ee3\u7801\u4e86\uff01\uff01<\/strong><\/span>\uff09<\/h4>\n<p><a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ee-1.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-4528 size-full\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ee-1.jpg\" alt=\"\" width=\"980\" height=\"304\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ee-1.jpg 980w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ee-1-300x93.jpg 300w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ee-1-768x238.jpg 768w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2017\/03\/ee-1-240x75.jpg 240w\" sizes=\"auto, (max-width: 980px) 100vw, 980px\" \/><\/a><\/p>\n<h3>\u89e3\u51b3\u65b9\u6cd5\uff0c\u5982\u679c\u7528UTF-8\u7684\u8bdd\uff0c\u90a3\u4e48\u5c31\u8ba9\u5176\u9ed8\u8ba4\u53bb\u5427\uff1a<\/h3>\n<pre class=\"lang:delphi decode:true \">MyJson := MyHTTPClient.Post('https:\/\/blog.qdac.cc', MyList).ContentAsString(TEncoding.UTF8);<\/pre>\n<h2><strong>\u82e5\u4e0d\u662fUTF-8\uff0c\u6216\u8bb8\u6709\u591a\u91cd\u65b9\u6cd5\uff0c\u6211\u5f81\u96c6\u4e0b\uff0c\u8c01\u6709\u65b9\u6cd5 \u53ef\u4ee5\u8d34\u4e0b\u9762\uff1b\u6211\u4f1a\u66f4\u65b0\u5230\u8fd9\u7bc7\u535a\u5ba2\u4e0a\uff1b<\/strong><\/h2>\n","protected":false},"excerpt":{"rendered":"<p>\u6211\u4e00\u76f4\u90fd\u5728\u5bfb\u627e\u5404\u79cd\u4e1a\u52a1\u529f\u80fd\u7684\u6700\u7b80\u5355\u5199\u6cd5\uff0c [&hellip;]<\/p>\n","protected":false},"author":117,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[8,21],"tags":[],"class_list":["post-4518","post","type-post","status-publish","format-standard","hentry","category-delphi","category-misc"],"views":8033,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4518","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/users\/117"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4518"}],"version-history":[{"count":8,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4518\/revisions"}],"predecessor-version":[{"id":4532,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/4518\/revisions\/4532"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4518"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4518"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4518"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}