【发布时间】:2021-07-24 14:56:03
【问题描述】:
以下代码在 .NET 控制台应用程序中运行,但在 .NET 核心控制台应用程序中不运行。
在 .NET Core 控制台应用程序中,我收到错误消息
The operation was canceled
InnerException 是
Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request
var client = new HttpClient();
HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Get, "https://www.nseindia.com/option-chain");
httpRequestMessage.Headers.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)");
httpRequestMessage.Headers.Add("Accept", "text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5");
httpRequestMessage.Headers.Add("Accept-Language", "en-us,en;q=0.5");
httpRequestMessage.Headers.Add("Accept-Charset", "ISO-8859-1,utf-8;q=0.7,*;q=0.7");
var response = await client.SendAsync(httpRequestMessage);
【问题讨论】:
标签: api .net-core console-application httpclient sendasync