您的位置:首页 > 其它

解决The server committed a protocol violation. Section=ResponseStatusLine 的方法

2016-07-18 13:28 453 查看
编写了一个程序,用于抓取网页上的一些信息,原来运行的很正常,某一天发生了错误

HttpWebResponse.GetResponse() 抛出以下异常:

The server committed a protocol violation. Section=ResponseStatusLine

 

在网上查了好久,发现很多人遇到了这个问题

这个是因为微软没有容忍不符合RFC 822中的httpHeader必须以CRLF结束的规定的服务器响应。

Apparently the problem is that starting with .NET 1.1 SP2 the HTTP protocol usage has been made more strict and any issApparently the problem is that starting with .NET 1.1 SP2 the HTTP protocol usage has been made more strict and any issue ue in the HTTP headers
- such as returning only a CR intead of CRLF pair at the end of a header - apparently throws the header for a loop.

 

通过修改配置文件解决:

For windows form applcation, create a new configuration file [application name].exe.config in the same directory of execution file. For web application, please modify web.config like below:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<system.net>
<settings>
<httpWebRequest useUnsafeHeaderParsing= "true " />
</settings>
</system.net>
</configuration>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: