我正在解决这个错误:
https ://github.com/openstacknetsdk/openstack.net/issues/333
该问题涉及ProtocolViolationException
以下消息:
HTTP/1.0 协议不支持分块编码上传。
我发现我能够可靠地重现问题,我发出一个产生 502 响应代码的 Web 请求,然后调用使用带有分块编码的 POST 请求。我将此追溯到具有502 响应之后ServicePoint.HttpBehaviour
的值的属性。HttpBehaviour.HTTP10
我能够使用以下技巧(在catch
块中)解决问题。此代码“隐藏”ServicePoint
由失败请求创建的实例ServicePointManager
,强制它ServicePoint
为下一个请求创建一个新实例。
public void TestProtocolViolation()
{
try
{
TestTempUrlWithSpecialCharactersInObjectName();
}
catch (WebException ex)
{
ServicePoint servicePoint = ServicePointManager.FindServicePoint(ex.Response.ResponseUri);
FieldInfo table = typeof(ServicePointManager).GetField("s_ServicePointTable", BindingFlags.Static | BindingFlags.NonPublic);
WeakReference weakReference = (WeakReference)((Hashtable)table.GetValue(null))[servicePoint.Address.GetLeftPart(UriPartial.Authority)];
if (weakReference != null)
weakReference.Target = null;
}
TestTempUrlExpired();
}
问题:
- 为什么我要观察这种行为?
- 解决问题的非hacky方法是什么?