zoukankan      html  css  js  c++  java
  • c# winform 服务器提交了协议冲突. Section=ResponseStatusLine

    【转】

    最近在用.net写一个网络蜘蛛,发现对有的网站用HttpWebrequest抓取网页的时候会报错,捕获异常提示:"服务器提交了协议冲突 Section=ResponseStatusLine ”,改用WebClient也是同样问题,后来知道,WebClient是对HttpWebrequest进一步进行了封装。
    最后终于找到问题根源:The  server  committed  a  protocol  violation.  Section=ResponseHeader  Detail=CR  must  be  followed  by  LF 微软没有容忍不符合RFC  822中的httpHeader必须以CRLF结束的规定的服务器响应。
    通过修改配置文件解决:在app.config或config.Config , 文件在项目的binDebug目录下;(WinForm)或web.config(Web)文件里修改。

    WinForm下的app.config文件中添加:

    <system.net>
        <settings>
          <httpWebRequest useUnsafeHeaderParsing="true" />
        </settings>
      </system.net>

    完整 app.config文件
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
    <system.net> 
            <settings> 
                   <httpWebRequest useUnsafeHeaderParsing="true" />
            </settings> 
        </system.net>
    </configuration>


    编译以后会在Debug下面自动创建一个 程序名.exe.config 的配置文件
    希望大家能少走弯路,Good Luck~

  • 相关阅读:
    P1093 奖学金
    华容道
    回文数
    P1654 OSU!
    Noip P1063 能量项链
    Noip 寻宝
    NOIP 2009 普及组 第三题 细胞分裂
    拦截器
    OGNL
    Struts2 配置详解
  • 原文地址:https://www.cnblogs.com/lj821022/p/8372247.html
Copyright © 2011-2022 走看看