惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

博客园 - 叶小钗
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Microsoft Security Blog
Microsoft Security Blog
罗磊的独立博客
大猫的无限游戏
大猫的无限游戏
美团技术团队
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
aimingoo的专栏
aimingoo的专栏
腾讯CDC
WordPress大学
WordPress大学
Apple Machine Learning Research
Apple Machine Learning Research
F
Fortinet All Blogs
G
Google Developers Blog
MongoDB | Blog
MongoDB | Blog
Microsoft Azure Blog
Microsoft Azure Blog
小众软件
小众软件
Engineering at Meta
Engineering at Meta
博客园_首页
B
Blog RSS Feed
D
Docker
M
MIT News - Artificial intelligence
爱范儿
爱范儿
I
InfoQ

博客园 - 快乐家++

QMT A股 量化程序开发资料 通过 PyWenCai 模块采集问财涨停数据的例子 均线粘合 【通达信】 MS-SQL事务处理语句 SQL Update:使用一个表的数据更新另一张表 CefSharp 使用备忘录 IIS7 伪静态 web.config 配置方法 针对不同.NET版本的条件编译 将Json数据 填充到 实例类 的函数 带查询参数 可分页 的 T-SQL 语句写法 当鼠标经过表格数据行时颜色不同且奇偶行颜色也不同 (纯CSS) JavaScript 版本的 RSA加密库文件 电工葵花宝典 一开关接线方法 c# 执行javascript 脚本 秒转换成时分秒 SQL2008中Merge的用法 C#将exe运行程序嵌入到自己的winform窗体中 如何让用户只能访问特定的数据库(MSSQL) 委托、回调 Lambda表达式书写方式
HttpWebRequest出错 服务器提交了协议冲突. Section=Response...
快乐家++ · 2016-12-08 · via 博客园 - 快乐家++

服务器提交了协议冲突. 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); } } } } }