Delphi 10.1 Further improves the HTTP access control Tnethttpclient from Delphi 10, which supports asynchronous access while increasing the ConnectionTimeout and responsetimeout two timeout properties. You might ask, what's this? Other languages have already been, and I think of really do not look at these regular functions increase, he can cross-platform ah, familiar with the Delphi cross-platform developers One said that it is cross-Win,osx,android,ios, Linux at the end of this year. I said too much, as if to persuade you to use Delphi as well.
Let's look at how to use asynchronous processing of HTTP requests.
1. Set Asynchronous=ture, the default value is False.
2. Make an HTTP request:
Ss:=tstringstream;
Nethttpclient1.get (' http://www.baidu.com ', SS);
Here, the SS parameter is optional, can not be filled, if filled, the request is completed, the result is returned in the SS.
3. The onrequestcompleted event in NetHttpClient1 receives the result:
This event is when the request completes the trigger, and the event parameter aresponse is the result stream that is returned. The SS can also be used as the result if the request is made with a parameter that receives the return stream, such as the SS above.
Looking for help, the Get method returns an interface object through which the Contentstream of the object can also handle the return result.
In summary, there are three ways to receive the results:
1. Receive the parameter with get
2. Receive with the return value of Get
3. Use the Requestcompleted event parameter to receive
In order to know when the request is completed, it is necessary to use this requestcompleted event, a friend said, this call fragmentation, not conducive to coding, how to use the current commonly used directly support asynchronous writing, directly callback the specified method. I think wrapping the nethttpclient into a common process, supporting the callback function is OK, like this, and then using the Nethttpclient object in this method to execute the Aurl, callback Acallbackmethod in the completion event:
Procedure Executehttprequest (Aurl:string;acallbackmethod);
Http://blog.sina.com.cn/s/blog_44fa172f0102w0ku.html
Tnethttpclient supports asynchronous access (Delphi 10.1 Berlin, Red Fish blog)