HttpClient响应状态417:期望失败 [英] HttpClient reponse status 417: Expectation failed

查看:205
本文介绍了HttpClient响应状态417:期望失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用httpclient将数据发布到远程服务器时,远程服务器返回错误:(417)期望失败。

When I used httpclient to post data to remote server, the remote server returned an error: (417) Expectation Failed.

实际上,有些用户得到了正确的结果,但有些人得到了上述错误,因为应用程序分发到很多地方。

Actually, some users got the correct result, but some got above error, since the app distributed to lots of places.

搜索问题很多,找到了很好的解决方法:
http://www.codeproject.com/Articles/94235/The-request-failed-with-HTTP- status-417-Expectatio

Googled the problem much, find the nice workaround: http://www.codeproject.com/Articles/94235/The-request-failed-with-HTTP-status-417-Expectatio

但我的问题是这个问题的真正长期解决方案是什么?

But my question is what's the really long term solution for this issue?

为什么代理服务器会响应此错误?它不支持Http 1.1
仅支持
?或者它不是整个Http 1.1。

Why the proxy server response this error? It does not support Http 1.1 Expect only? or it does not the overall Http 1.1.

如果是后者,我们应该切换到Http 1.0或更低的协议版本吗?

If it is the later, should we switch to the Http 1.0 or lower protocol version?

应该HttpClient api在内部处理此问题,例如,当它找到代理服务器响应417,或者代理服务器只支持Http 1.0时,只需禁用此属性或切换到较低的http协议版本?

Should HttpClient api handle this problem internal, for example, when it find the proxy server response 417, or the proxy server only support Http 1.0, just disable this property or switch to lower http protocol version?

因为这种错误很难追踪。

Because this kind of error is much hard to track.

有人在您的应用中遇到同样的问题吗?

Is anybody meet the same problem in your app, any idea?

谢谢很多。

推荐答案

我使用此代码它应该适用于您的场景:

I use this code and it should work for your scenario:

            using (HttpClient client = new HttpClient(mHandler))
            {
                client.MaxResponseContentBufferSize = 100000;

                HttpRequestMessage message = new HttpRequestMessage(HttpMethod.Post, pUrl);
                message.Headers.ExpectContinue = false;

                message.Content = new StringContent(pParameters);
                message.Content.Headers.ContentLength = pParameters.Length;

                response = await client.SendAsync(message);
            }





这篇关于HttpClient响应状态417:期望失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆