服务器提交了协议冲突. Section=ResponseStatusLine,WebClient使用Cookie
来源:互联网 发布:聊天室源码 编辑:程序博客网 时间:2024/05/22 02:30
自己写了个程序,利用post获取某网站的信息,当进行到httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse()时会提示“服务器提交了协议冲突. Section=ResponseStatusLine”(有时出有时不出,好像跟电脑或网络有关)
好了,下面是我自己解决的办法:
百度了下,几个人都说要改webclient等来提交请求,但我仍想利用httpWebRequest.GetResponse(),不想改其他代码了.
关于“”错误,百度上很多人都是说使用下面的代码解决,但是我用了都不成功,不知道是为什么。我估计不是好的解决方法。
WinForm下的app.config文件中添加:<system.net> <settings> <httpWebRequest useUnsafeHeaderParsing="true" /> </settings> </system.net>
好了,下面是我自己解决的办法:
这里可以使用webclient,只要有cookies功能就可以了,我们可以加上cookies功能,如下代码。这样Section=ResponseStatusLine问题也可以解决了。二全其美。
public class WebClientPlus : WebClient { private CookieContainer m_container = new CookieContainer(); public CookieContainer CookieContainer { get { return m_container; } set { m_container = value; } } [System.Security.SecuritySafeCritical]//重要 public WebClientPlus() : base() { } protected override WebRequest GetWebRequest(Uri address) { WebRequest request = base.GetWebRequest(address); if (request is HttpWebRequest) { (request as HttpWebRequest).CookieContainer = m_container; } return request; } }
- 服务器提交了协议冲突. Section=ResponseStatusLine,WebClient使用Cookie
- 服务器提交了协议冲突. Section=ResponseStatusLine
- 服务器提交协议冲突 Section=ResponseStatusLine 的解决办法
- 服务器提交协议冲突 Section=ResponseStatusLine 的解决办法
- 服务器提交协议冲突 Section=ResponseStatusLine 的解决办法
- 关于“服务器提交了协议冲突. Section=ResponseStatusLine"问题请
- C# Winform/Server 提交协议冲突 Section=ResponseStatusLine 的解决,可能是服务器引起的异常
- 服务器提交了协议冲突.Section=ResponseHeader Detail=CR 后面必须是LF
- 服务器提交了协议冲突.Section=ResponseHeader Detail=CR后面必须是LF
- 服务器提交了协议冲突.Section=ResponseHeader Detail=CR 后面必须是LF .
- C# 服务器提交了协议冲突Section=ResponseHeader Detail=CR 后面必须 LF
- ASP.NET 中抓取网页内容 并出现服务器提交了协议冲突. Section=ResponseHeader 解决方案
- 服务器提交了协议冲突,解决方法
- 服务器提交了协议冲突. 终极解决方案
- 服务器提交了协议冲突. 终极解决方案
- Section=ResponseStatusLine的解决
- 基础连接已经关闭: 该服务器提交了 HTTP 协议冲突?
- FTP之‘基础连接已关闭:服务器提交了协议冲突’错误探析
- hdu 1867 (KMP)
- Allegro最新资料大全
- Android-sqlite数据库存取图片信息
- 02.IOS学习笔记之C语言概述
- c/c++ 字符 字符串
- 服务器提交了协议冲突. Section=ResponseStatusLine,WebClient使用Cookie
- cocos2d-x的AssetsManager分析
- Objective-C 4封装、继承、多态
- 编程部分---PHP
- 信号量的操作——semop函数
- 快速矩阵幂
- java第十三天_集合,List集合
- windows下信号量的使用
- 黑马程序员_I/O流(递归、配置文件、流的合并拆分)