现在我的Post请求失败了(我只会附加一个,但我有大约4个Post请求,其中每个人都因为同样的原因而失败)
编辑:我刚刚测试了我的Get请求,产生了同样的错误..
这是我的代码:
using (var client = new HttpClient()) { Field fld = new Field() { ... }; Forjson bodyFormat = new Forjson() { ... }; string output = JsonConvert.SerializeObject(bodyFormat); StringContent sc = new StringContent(output,Encoding.UTF8,"application/json"); try { client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic",Convert.ToBase64String( Encoding.ASCII.GetBytes( string.Format("{0}:{1}","XX","YY")))); response = await client.PostAsync("https:...",sc); // It fails here
错误消息是:
attempt Failed because the connected party did not properly respond after a period of time,or established connection Failed because connected host has Failed to respond
我试过谷歌搜索这个错误,但每个帖子似乎都没有与我相关..他们谈论权限防火墙和端口,但为什么它会在一个项目中工作而在另一个项目中不工作?
如果我通过Postman /我的1.1版本的项目备份尝试,那么它的工作原理.
解决方法
attempt Failed because the connected party did not properly respond after a period of time,or established connection Failed because connected host has Failed to respond
对于此错误,它是由核心1.1和核心2.1之间的更改引起的,httpclienthandler从WinHttpHandler更改为SocketsHttpHandler.
对于变通方法,您可以尝试配置进程以使用较旧的httpclienthandler
AppContext.SetSwitch("System.Net.Http.UseSocketsHttpHandler",false); using (var client = new HttpClient())
错误跟踪:.NET Core 2.1 SocketsHttpHandler proxy authentication using Windows auth is broken #30166
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。