Section=ResponseHeader detail beat love=CR 后面必须是 LF

显示行号 复制代码 ? 处理『服务器提交了协议冲突』
#region 处理『服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF』
//需引用 using System.R
public static bool SetAllowUnsafeHeaderParsing()
//Get the assembly that contains the internal class
Assembly aNetAssembly = Assembly.GetAssembly(
typeof(System.Net.Configuration.SettingsSection));
if (aNetAssembly != null)
//Use the assembly in order to get the internal type for
// the internal class
Type aSettingsType = aNetAssembly.GetType(
"System.Net.Configuration.SettingsSectionInternal");
if (aSettingsType != null)
//Use the internal static property to get an instance
// of the internal settings class. If the static instance
// isn't created allready the property will create it for us.
object anInstance = aSettingsType.InvokeMember("Section",
BindingFlags.Static | BindingFlags.GetProperty
| BindingFlags.NonPublic, null, null, new object[] { });
if (anInstance != null)
//Locate the private bool field that tells the
// framework is unsafe header parsing should be
// allowed or not
FieldInfo aUseUnsafeHeaderParsing = aSettingsType.GetField(
"useUnsafeHeaderParsing",
BindingFlags.NonPublic | BindingFlags.Instance);
if (aUseUnsafeHeaderParsing != null)
aUseUnsafeHeaderParsing.SetValue(anInstance, true);
return true;
return false;
#endregion
还没有评论.
还没有引用.服务器提交协议冲突 Section=ResponseStatusLine 的解决办法
  最近写程序抓取数据,发现对有的网站用HttpWebrequest抓取网页的时候会报错,捕获异常提示:"服务器提交了协议冲突 Section=ResponseStatusLine ”,改用WebClient也是同样问题,后来知道,WebClient是对HttpWebrequest进一步进行了封装。最后终于找到问题根源:The
violation.
Section=ResponseHeader
LF 微软没有容忍不符合RFC
822中的httpHeader必须以CRLF结束的规定的服务器响应。通过修改配置文件解决:在app.config(WinForm)或web.config(Web)文件里修改。WinForm下的app.config默认不存在,手动在Debug文件夹所在的同级目录下新建一个XML配置文件,内容为:& xml version="1.0" encoding="utf-8"
&&configuration&&system.net&
&settings&
&httpWebRequest
useUnsafeHeaderParsing= "true "
&/settings&
&/system.net&&/configuration&编译以后会在Debug下面自动创建一个 程序nfig 的配置文件查看: 4815|回复: 2
服务器提交了协议冲突. Section=ResponseHeader Detail=标头名称无效
TA的每日心情开心昨天&08:14签到天数: 71 天[LV.6]常住居民II
小小程序员() 11:06:51
我的代码:string url = &http://192.168.0.184/cgi-bin/wagent?webipcinfo+list&;
& && && && &HttpHelper httpHelper = new HttpHelper();
& && && && &HttpItem item=new HttpItem ();
& && && && &item.URL=
& && && && &item.ResultType = ResultType.S
& && && && &HttpResult r = httpHelper.GetHtml(item);
小小程序员() 11:07:20
它提示:服务器提交了协议冲突. Section=ResponseHeader Detail=标头名称无效
PerkySu() 11:08:13
ContentType = &text/html&这个参数没有设置
PerkySu() 11:09:05
要返回什么样的数据要写成什么样的头信息的。
PerkySu() 11:09:09
/thread-.html
小小程序员() 11:10:13
设置了也不行
小小程序员() 11:10:57
还是提示:服务器提交了协议冲突. Section=ResponseHeader Detail=标头名称无效
PerkySu() 11:12:52
myRequest.ContentType = &application/x-www-form-urlencoded&;
PerkySu() 11:13:04
item.ContentType = &application/x-www-form-urlencoded&
PerkySu() 11:13:45
[code=csharp]服务器提交了协议冲突.Section=ResponseHeader Detail=CR 后面必须是LF.
微软没有容忍不符合RFC 822中的httpHeader必须以CRLF结束的规定的服务器响应所导致.
解决方案分别是在web.config配置
& & &system.net&
& & &settings&
& & &httpWebRequest useUnsafeHeaderParsing=”true” /&
& & &/settings&
& & &/system.net&
PerkySu() 11:14:13
我建议你去看看Httphelper原理再写,要不然你的问题让我很头疼。
PerkySu() 11:14:20
问的很另类
小小程序员() 11:14:26
小小程序员() 11:17:44
在Config中配置下,可以了
小小程序员() 11:17:55
谢谢,老大
小小程序员() 11:18:24
苏飞你真是程序员的福音啊
本帖被以下淘专辑推荐:
& |主题: 50, 订阅: 8
TA的每日心情开心昨天&08:14签到天数: 71 天[LV.6]常住居民II
[code=csharp]服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF&&
The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF&&
主体意思是微软没有容忍不符合RFC 822中的httpHeader必须以CRLF结束的规定的服务器响应。&&
解决方案是在app.config或web.config文件里加入
&configuration&
& & &system.net&
& && &&&&settings&
& && && && &&httpWebRequest useUnsafeHeaderParsing=&true& /&
& && &&&&/settings&
& & &/system.net&
&/configuration&&?xml version=&1.0& encoding=&utf-8& ?&
&configuration&
& & &system.net&
& && &&&&settings&
& && && && &&httpWebRequest useUnsafeHeaderParsing=&true& /&
& && &&&&/settings&
& & &/system.net&
&/configuration&
允许系统容忍(tolerant)只以CR或LF结尾的hearder信息&&[/code]
该用户从未签到
现在没时间看,先留个记号,回头细细品味!
( 豫ICP备号-1)c# - The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF, In WinForms? - Stack Overflow
to customize your list.
Announcing Stack Overflow Documentation
We started with Q&A. Technical documentation is next, and we need your help.
Whether you're a beginner or an experienced developer, you can contribute.
I am trying to use a WebClient / HttpWebRequest to download some data from a server. I use the following code to do so:
WebClient client = new WebClient();
client.Credentials = new NetworkCredential("admin", "password");
Stream datastream = client.OpenRead("/cgi-bin/CF_logs.html");
StreamReader reader = new StreamReader(datastream);
The server is my page is in my router's configuration. It works fine from a browser, but when downloaded using my code it throws a WebException with the message
The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF, In WinForms?.
I have found a solution one would use if they were using ASP.net, adding the following to web.config:
&configuration&
&system.net&
&settings&
&httpWebRequest useUnsafeHeaderParsing="true" /&
&/settings&
&/system.net&
&/configuration&
However, I am making a WinForms app so this won't work for me. What alternatives are there to fix this problem?
1,46552258
First, adding an app.config file is just as easy as adding any other file,
Then you just have to add that code snippet above to that new app.config.
Another way of setting that property via code, avoiding the need for an app.config is shown
3,67911730
Your Answer
Sign up or
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Post as a guest
By posting your answer, you agree to the
Not the answer you're looking for?
Browse other questions tagged
Stack Overflow works best with JavaScript enabled}

我要回帖

更多关于 detail beat love 的文章

更多推荐

版权声明:文章内容来源于网络,版权归原作者所有,如有侵权请点击这里与我们联系,我们将及时删除。

点击添加站长微信