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

1.在app.config种添加 web 在 web.config种添加

 <system.net>
    <settings>
      <httpWebRequest useUnsafeHeaderParsing="true" />
    </settings>
  </system.net>
 
2.以反射的形式在程序中设定useUnsafeHeaderParsing的值【该方法须在发送请求之前进行设定否则无效果】
public static bool SetAllowUnsafeHeaderParsing(bool useUnsafe)
{
//Get the assembly that contains the internal class
System.Reflection.Assembly aNetAssembly = System.Reflection.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",
System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.GetProperty | System.Reflection.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
System.Reflection.FieldInfo aUseUnsafeHeaderParsing = aSettingsType.GetField("useUnsafeHeaderParsing", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (aUseUnsafeHeaderParsing != null)
{
aUseUnsafeHeaderParsing.SetValue(anInstance, useUnsafe);
return true;
}
}
}
}
return false;
}

以上摘抄于http://www.cnblogs.com/lewisli/p/6775010.html

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

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

    服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF  The server committed a protocol violation. Se ...

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

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

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

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

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

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

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

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

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

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

  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. bootstrap 弹出框实现点击后打开离开后关闭

    $("#PersonName").popover({ trigger: 'manual', placement: 'bottom', //title: '<div style ...

  2. easyui datagrid 取消删除的方法

    下面为取消方法 ... { field: 'Guid', title: '操作', width: 80, align: 'center', formatter: function (value, ro ...

  3. TOP100summit:【分享实录-猫眼电影】业务纵横捭阖背后的技术拆分与融合

    王洋:猫眼电影商品业务线技术负责人.技术专家.主导了猫眼商品供应链和交易体系从0到1的建设,并在猫眼与美团拆分.与点评电影业务融合过程中,从技术层面保障了商品业务的平稳切换,同时也是美团点评<领 ...

  4. .NET Core类库项目中如何读取appsettings.json中的配置

    这是一位朋友问我的问题,写篇随笔回答一下.有2种方法,一种叫丑陋的方法 —— IConfiguration ,一种叫优雅的方法 —— IOptions . 1)先看丑陋的方法 比如在 RedisCli ...

  5. [No000012F]WPF(7/7) - 样式,触发器和动画

    WPF Tutorial : Beginning [^] WPF Tutorial : Layout-Panels-Containers & Layout Transformation [^] ...

  6. [No0000F3]C# 结构(Struct)

    在 C# 中,结构是值类型数据结构.它使得一个单一变量可以存储各种数据类型的相关数据.struct关键字用于创建结构. 结构是用来代表一个记录.假设您想跟踪图书馆中书的动态.您可能想跟踪每本书的以下属 ...

  7. springboot程序无法访问静态资源

    今天开发遇到了一个很奇葩的错误,再spngboot程序成功运行后发现无法访问再resouces/static下的静态资源,通过rul访问总是404,原因最终锁定在某配置类的一个标签上: @Enable ...

  8. python实现单链表反转(经典笔试题)

    https://blog.csdn.net/su_bao/article/details/81072849 0.说在前面的话 链表结构,说难不难,说易不易,一定要亲自编程实现一下.其次就是一定要耐心, ...

  9. javascript高级技巧篇(作用域安全、防篡改、惰性载入、节流、自定义事件,拖放)

    安全的类型检测 在任何值上调用Object原生的toString()方法,都会返回一个[object NativeConstructorName]格式字符串.每个类在内部都有一个[[Class]]属性 ...

  10. 【pyqtgraph绘图】案例-动态的正余弦波形图

    先看一个简单的小例子: 完整代码: import numpy as np import pyqtgraph as pg import sys from PyQt5.QtWidgets import Q ...