问题
I am using the HttpClient to communicate with a GoPro Camera over WiFi, but I am getting the following error. "The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF" Although I have notified them, I cannot change GoPro's web server, so I need to resolve/ignore this on the client side. When i make this call, using Fiddler as a proxy, Fiddler corrects the issue and my app runs as expected. But without fiddler i get the protocol violation message.
From the searching i have done this can be resolved by adding <httpWebRequest useUnsafeHeaderParsing = "true"/>
(see HttpWebRequestElement.UseUnsafeHeaderParsing Property), but this is a Windows 8 store app and there is no configuration file.
One option is to write a custom handler and inject it into the HttpClient ctor, but I am not sure where to start with my own custom handler and it seems like a big effort for something that should be built in.
Is there a simple solution?
回答1:
I haven't tried it myself but maybe you can change the element by code like this http://social.msdn.microsoft.com/Forums/en-US/ff098248-551c-4da9-8ba5-358a9f8ccc57/how-do-i-enable-useunsafeheaderparsing-from-code-net-20
回答2:
Unfortunately writing your own handler doesn't work either because the system's HttpClientHandler
gets called before your custom one when the response is returned.
For Windows Store apps, you can use MessageWebSocket
: I attempted something similar for Windows Phone 8.1 Silverlight using StreamSocket
; see How can I accept "unsafe" HTTP response headers in a Windows Phone/Store app?
来源:https://stackoverflow.com/questions/18580016/httpclient-server-committed-a-protocol-violation-section-responseheader-detail