我有一个像这样的httpclient:
I have an httpclient like this :
var client = new HttpClient();我这样张贴:
var result = client.PostAsync( endpointUri, requestContent);并获得如下响应:
HttpResponseMessage response = result.Result;我知道此调用将阻塞线程,这就是线程应该如何工作的(只需为自己构建工具,不需要异步线程即可)
I understand this call will block the thread, thats how its supposed to work (just building a tool for myself, no async threads needed)
我第一次运行此呼叫,大约需要2分钟才能得到结果.同时,如果我在其他地方进行完全相同的调用,则它会在200毫秒内完成.即使我点击了google,也需要2分钟.但是,在第一个通话之后,只要我保持应用程序打开,任何其他通话都可以.当我打开应用程序时,它只是第一次校准.可能是什么原因造成的?
The first time I run this call, it takes about 2 minutes to get a result. Meanwhile, if I do the exact same call elsewhere its done in 200ms. Even if I hit google, it takes 2 minutes. But, after the first call, as long as I keep the app open any additional calls are good. Its just the first cal when I open the application. What could be causing this?
推荐答案问题是,它在尝试为客户端解析代理时挂了很长时间.像这样初始化HttpClient可以达到目的:
The problem was that it was hanging for a very long time trying to resolve a proxy for the client. Initializing the HttpClient like this did the trick:
var client = new HttpClient(new HttpClientHandler { UseProxy = false });更多推荐
为什么在我的C#winforms应用程序中第一次HttpClient.PostAsync调用极其缓慢?
发布评论