{"id":3837,"date":"2016-04-22T13:30:03","date_gmt":"2016-04-22T05:30:03","guid":{"rendered":"http:\/\/blog.qdac.cc\/?p=3837"},"modified":"2016-04-22T13:33:45","modified_gmt":"2016-04-22T05:33:45","slug":"%e8%bd%ac%e7%ba%a2%e9%b1%bc%e5%84%bf%ef%bc%9atnethttpclient%e6%94%af%e6%8c%81%e5%bc%82%e6%ad%a5%e8%ae%bf%e9%97%aedelphi-10-1-berlin","status":"publish","type":"post","link":"https:\/\/blog.qdac.cc\/?p=3837","title":{"rendered":"[\u8f6c]\u7ea2\u9c7c\u513f\uff1aTNetHttpClient\u652f\u6301\u5f02\u6b65\u8bbf\u95ee(Delphi 10.1 Berlin)"},"content":{"rendered":"<p>\u8bbf\u95ee\u539f\u6587\u8bf7\u70b9\u51fb <a href=\"http:\/\/blog.sina.com.cn\/s\/blog_44fa172f0102w0ku.html\">\u8fd9\u91cc<\/a><\/p>\n<p>Delphi 10.1\u8fdb\u4e00\u6b65\u6539\u8fdb\u81eaDelphi 10\u5e26\u6765\u7684Http\u8bbf\u95ee\u63a7\u4ef6TNetHttpClient\uff0c\u652f\u6301\u5f02\u6b65\u8bbf\u95ee\uff0c\u540c\u65f6\u589e\u52a0ConnectionTimeout\u53caResponseTimeout\u4e24\u4e2a\u8d85\u65f6\u5c5e\u6027\u3002\u4f60\u4e5f\u8bb8\u4f1a\u95ee\uff0c\u8fd9\u6709\u4ec0\u4e48\uff1f\u5176\u4ed6\u7684\u8bed\u8a00\u65e9\u5c31\u6709\u4e86\uff0c\u800c\u6211\u60f3\u5230\u7684\u786e\u5b9e\u522b\u770b\u8fd9\u4e9b\u5e38\u89c4\u7684\u529f\u80fd\u589e\u52a0\uff0c\u4ed6\u53ef\u4ee5\u8de8\u5e73\u53f0\u7684\u554a\uff0c\u719f\u77e5Delphi\u8de8\u5e73\u53f0\u7684\u5f00\u53d1\u8005\u4e00\u8bf4\u5c31\u660e\u767d\uff0c\u8fd9\u662f\u8de8win,osx,android,ios\u7684\uff0c\u4eca\u5e74\u5e95\u8fd8\u8981linux.\u6211\u53c8\u8bf4\u591a\u4e86\uff0c\u597d\u8c61\u529d\u4f60\u4e5f\u6765\u7528delphi\u4f3c\u7684\u3002<\/p>\n<p>\u6211\u4eec\u770b\u4e00\u4e0b\u5982\u4f55\u4f7f\u7528\u5f02\u6b65\u5904\u7406Http\u8bf7\u6c42\u3002<\/p>\n<ol>\n<li>\u8bbe\u7f6eAsynchronous=true,\u9ed8\u8ba4\u503c\u662fFalse.<br \/>\n<a href=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2016\/04\/d10.1nethttpclient.png\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-3838\" src=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2016\/04\/d10.1nethttpclient.png\" alt=\"d10.1nethttpclient\" width=\"393\" height=\"431\" srcset=\"https:\/\/blog.qdac.cc\/wp-content\/uploads\/2016\/04\/d10.1nethttpclient.png 393w, https:\/\/blog.qdac.cc\/wp-content\/uploads\/2016\/04\/d10.1nethttpclient-274x300.png 274w\" sizes=\"auto, (max-width: 393px) 100vw, 393px\" \/><\/a><\/li>\n<li>\u53d1\u51fahttp\u8bf7\u6c42\uff1a\n<pre class=\"lang:delphi decode:true\">ss:=TStringStream;\r\nNetHttpClient1.Get('http:\/\/www.baidu.com',ss);<\/pre>\n<p>\u8fd9\u91cc\uff0cSS\u53c2\u6570\u662f\u4efb\u9009\u7684\uff0c\u53ef\u4e0d\u586b\uff0c\u5982\u679c\u586b\u4e0a\uff0c\u8bf7\u6c42\u5b8c\u6210\u65f6\uff0c\u8fd4\u56de\u7ed3\u679c\u5728SS\u4e2d\u3002<\/li>\n<li>\u5728NetHttpClient1\u7684OnRequestCompleted\u4e8b\u4ef6\u63a5\u6536\u7ed3\u679c<\/li>\n<\/ol>\n<p>\u770b\u5e2e\u52a9\uff0cGet\u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u63a5\u53e3\u5bf9\u8c61\uff0c\u901a\u8fc7\u8fd9\u4e2a\u5bf9\u8c61\u7684ContentStream\u4e5f\u53ef\u4ee5\u5904\u7406\u8fd4\u56de\u7ed3\u679c\u3002<\/p>\n<p>\u603b\u7ed3\u4e0a\u9762\uff0c\u5c31\u662f\u6709\u4e09\u79cd\u65b9\u5f0f\u6765\u63a5\u6536\u7ed3\u679c\uff1a<\/p>\n<ol>\n<li>\u7528Get\u7684\u53c2\u6570\u6765\u63a5\u6536<\/li>\n<li>\u7528Get\u7684\u8fd4\u56de\u503c\u63a5\u6536<\/li>\n<li>\u5229\u7528RequestCompleted\u4e8b\u4ef6\u53c2\u6570\u6765\u63a5\u6536<\/li>\n<\/ol>\n<p>\u4e3a\u4e86\u77e5\u9053\u8bf7\u6c42\u4f55\u65f6\u5b8c\u6210\uff0c\u90fd\u8981\u7528\u5230\u8fd9\u4e2aRequestCompleted\u4e8b\u4ef6\uff0c\u6709\u670b\u53cb\u8bf4\uff0c\u8fd9\u6837\u8c03\u7528\u788e\u7247\u5316\uff0c\u4e0d\u5229\u4e8e\u7f16\u7801\uff0c\u5982\u4f55\u5229\u7528\u73b0\u5728\u5e38\u7528\u7684\u76f4\u63a5\u652f\u6301\u5f02\u6b65\u7684\u5199\u6cd5\uff0c\u76f4\u63a5\u56de\u8c03\u6307\u5b9a\u7684\u65b9\u6cd5\u3002\u6211\u8ba4\u4e3a\u5c06NetHttpClient\u5c01\u88c5\u5230\u4e00\u4e2a\u901a\u7528\u7684\u8fc7\u7a0b\u4e2d\uff0c\u652f\u6301\u56de\u8c03\u51fd\u6570\u5c31\u884c\u4e86,\u7c7b\u4f3c\u4e0b\u9762\u8fd9\u6837\uff0c\u7136\u540e\u5728\u8fd9\u4e2a\u65b9\u6cd5\u4e2d\u4f7f\u7528NetHttpClient\u5bf9\u8c61\u6267\u884caUrl,\u5728\u5b8c\u6210\u4e8b\u4ef6\u4e2d\u56de\u8c03aCallBackMethod\uff1a<br \/>\nprocedure ExecuteHttpRequest(aUrl:string;aCallBackMethod);<\/p>\n<p><span style=\"color: #ff0000;\">[\u4ffa\u7ed9\u5907\u6ce8\u4e0b]<\/span><\/p>\n<p><span style=\"color: #ff0000;\">\u5b9e\u9645\u4e0a TNetHttpClient \u5c01\u88c5\u7684\u662f THttpClient\uff0c\u4f60\u5728\u4ee3\u7801\u4e2d\u76f4\u63a5\u7528 THttpClient.BeginGet\uff0c\u5b83\u6709\u533f\u540d\u51fd\u6570\u7684\u56de\u8c03\u7248\u672c\uff0c\u8be6\u7ec6\u4fe1\u606f\u770b\u5e2e\u52a9\u3002<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u8bbf\u95ee\u539f\u6587\u8bf7\u70b9\u51fb \u8fd9\u91cc Delphi 10 [&hellip;]<\/p>\n","protected":false},"author":1,"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":[69,8,603,21],"tags":[606,424,607],"class_list":["post-3837","post","type-post","status-publish","format-standard","hentry","category-c-builder","category-delphi","category-603","category-misc","tag-berlin","tag-http","tag-607"],"views":7580,"_links":{"self":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/3837","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\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3837"}],"version-history":[{"count":3,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/3837\/revisions"}],"predecessor-version":[{"id":3842,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=\/wp\/v2\/posts\/3837\/revisions\/3842"}],"wp:attachment":[{"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3837"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3837"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.qdac.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3837"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}