服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF

The server committed a protocol violation. Section=ResponseHeader Detail=CR must be followed by LF

主体意思是微软没有容忍不符合RFC 822中的httpHeader必须以CRLF结束的规定的服务器响应。

一个解决方案是在application.config或web.config文件里加入

<system.net>

<settings>

<httpWebRequest useUnsafeHeaderParsing="true" />

</settings>

</system.net>

允许系统容忍(tolerant)只以CR或LF结尾的hearder信息

using System.Reflection;

        bool GetAllowUnsafeHeaderParsing()
{
//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)
return (bool)aUseUnsafeHeaderParsing.GetValue(anInstance);
}
}
}
return false;
}
void SetAllowUnsafeHeaderParsing(bool val)
{
//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, val);
}
}
}
}
}

HttpWebRequest出错 服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF的更多相关文章

  1. 关于 服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF 错误

    用WebClient 去下载数据时发现有服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF错误,解决办法 1.在app.config种添加 we ...

  2. WebRequest请求错误(服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF)

    WebRequest请求错误(服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF)解决办法,天津config文件,增加一个配置如下 <?x ...

  3. 服务器提交了协议冲突. Section=ResponseHeader Detail=CR...的解决方案总结

    今天在HttpWebRequest发送一个网页请求的时候,HttpWebResponse返回了一个奇怪的错误信息: 这个Http协议请求类可是微软封装的,我使用的流程可是中规中矩,不可能是我写错代码, ...

  4. httpwebrequest 服务器提交了协议冲突. section=responsestatusline

    调用接口的时候,包: httpwebrequest 服务器提交了协议冲突. section=responsestatusline 解决方案: req.KeepAlive = false; req.Al ...

  5. 解决WebService/WCF调用时报错"服务器提交了协议冲突. Section=ResponseStatusLine"问题

    今天更新了一个网站,新增了一个页面,调用WebService,在测试环境好好的,部署到正式环境后就莫名报错: 服务器提交了协议冲突. Section=ResponseStatusLine 网上查了好多 ...

  6. c# winform 服务器提交了协议冲突. Section=ResponseStatusLine

    [转] 最近在用.net写一个网络蜘蛛,发现对有的网站用HttpWebrequest抓取网页的时候会报错,捕获异常提示:"服务器提交了协议冲突 Section=ResponseStatusL ...

  7. 关于“服务器提交了协议冲突. Section=ResponseStatusLine"问题

    你的问题的原因是这样的,ASP.Net 2.0 增强了安全性,对一些有危害的http 头进行了判断,比如url中有空格的情况,以帮助网站提高网络攻击的防御能力.如果你的http头中有一些ASP.NET ...

  8. C#调取接口时报错:服务器提交了协议冲突. Section=ResponseStatusLine

    private Dictionary<string, Object> GetLocation(string imei) { #region===代码=== string serviceAd ...

  9. 服务器提交了协议冲突。Section=ResponseHeader Detail=标头名称无效

    服务器提交了协议冲突.Section=ResponseHeader Detail=CR 后面必须是LF. 微软没有容忍不符合RFC 822中的httpHeader必须以CRLF结束的规定的服务器响应所 ...

随机推荐

  1. Frame动画实战

    Android动画分为Tween动画和Frame动画,Tween动画主要包括图片的放大缩小.旋转.透明度变化.移动等等操作:Frame动画则简单得多了,就是把一张张的图片连续播放产生动画效果. 本节主 ...

  2. ubuntu下修改进入root用户和修改文件权限

    (1)进入root用户 su root 密码:设置的root密码 (2)修改文件权限 sudo chmod +777  file (3)执行shell ./shellfile (4)编写shell 第 ...

  3. 关于IE9-解决background-size的问题

    body{background:url("/branch/comm/images-new/login.jpg") no-repeat;background-size:100%;fi ...

  4. [Java Basics3] XML, Unit testing

    What's the difference between DOM and SAX? DOM creates tree-like representation of the XML document ...

  5. Cosh.2

    没壳 直接拖 一开始  字符长度不对.   所以  输入都超过5   就没什么问题了 发现下面的跳转都是跳到eorr的 那不跳的条件呢 看来他们必须要相等.单步跟踪就会发现eax指向的是我们的Seri ...

  6. 一个简单的app自动登录Python脚本案例

  7. [BZOJ 2038]小Z的袜子

    传送门:BZOJ 2038 题意很明确,是在给定的区间内任意选取两个数,求选到两个相同的数的概率. 所以我们得首先统计在给定的区间内,相同的数对有多少对,那么这里就使用到了莫队算法.如果对莫队算法还不 ...

  8. JS控制的动态表格

    对应的js: function pccAddSignRow() { //读取最后一行的行号,存放在LearnTRLastIndex文本框中 var pccTRLastIndex = findObj(& ...

  9. LESS用法·

    CSS 彻底改变了 Web 页面的设计,但 CSS 仍然是静态的,而且在其句法发展方面受到限制.这些限制是有目的且合乎情理的,鼓励广泛加以实现.但开发人员和设计人员常常发现 CSS 使用起来很单调乏味 ...

  10. CoInitialize浅析一

    大家都知道程序中若要使用COM组件则必须要先调用CoInitialize,该函数主要是用来初始化COM运行环境.但这个函数的作用域是以线程为单位还是以进程为单位呢?也许大家已经通过测试程序摸索出答案, ...