开发者

ServerProtocolViolation error

开发者 https://www.devze.com 2022-12-16 04:54 出处:网络
I am hitting up a server wit开发者_运维百科h the following code and am encountering a ServerProtocolViolation error:

I am hitting up a server wit开发者_运维百科h the following code and am encountering a ServerProtocolViolation error:

// Prepare the webpage
HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url + queryString);

// execute the request
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

Does anyone know how to work around this kind of error?


This error means that the webserver that you're sending the request to isn't conforming to the HTTP standard.

Other than fixing the server or rewriting HttpWebRequest to be more generous, there isn't much you can do.

What URL are you requesting, and what's the text of the exception?

EDIT: If you request the URL in Fiddler, you'll see that the server didn't return any headers. You should contact the owner of the server and complain.

As a workaround, if you run Fiddler while sending the request, Fiddler will fix the response and allow HttpWebResponse to parse it.


Just a quick note on another reason that I experienced:

If you configure your request to use a proxy server (i.e. through the HttpWebRequest.Proxy property), and you use a wrong proxy port, there might also be a chance to see that error.

In my case, I configured http://127.0.0.1/ as the proxy but had the actual proxy server running on http://127.0.0.1:808/ instead (i.e. port "808" instead of "80").

If this is the case for you, try using no proxy or of course, configure the correct proxy port.

0

精彩评论

暂无评论...
验证码 换一张
取 消