Tnethttpclient supports asynchronous access (Delphi 10.1 Berlin, Red Fish blog)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.