"A task was cancelled" error when you resolve a. NET HttpClient call

Source: Internet
Author: User

Recently, the integration of Elasticclient client in the system, automatically create indexes, delete indexes, found that through elasticclient lowerlevelclient can not return the results correctly, but the index has been successfully created or deleted.

and will throw the exception "A task was cancelled" in the time-out period, check the official documents and Google are no solution.

Try again in the morning, use httpclient direct access, still the same problem.

Helpless, sacrifice fiddler, carry out request analysis.

1) Use composer to simulate the request, the simplest get operation, actually can not return the result immediately

2) direct access using the browser to return the results correctly

3) Compare the HTTP request header, the Fiddler request header is basically empty, from the browser to copy the Fiddler request header come over, finally found, plus the following request header, will be able to correctly return the results:

Accept-encoding:gzip, deflate

4) corresponding to the httpclient, you can use the following method to solve the

New Httpclienthandler ()            {                = Decompressionmethods.gzip | decompressionmethods.deflate            };             var New HttpClient (handler)            {                new Uri ($"http://{es_host}:{es_port}")            };

Use this httpclient to access the Elasticsearch and immediately return to the results.

problem Analysis: the server side will return the result by default using gzip compression, but the client does not handle data decompression by default, causing the client to read the data, can not tell whether the data has been read, has been suspended until the timeout, and then throw "A task was Canceled "error.

HttpClient Other "A task was Canceled" errors, most likely due to incorrect HTTP header settings, and the server has requirements for client features, such as gzip for this example.

"A task was cancelled" error when you resolve a. NET HttpClient call

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.