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

推荐订阅源

The GitHub Blog
The GitHub Blog
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Microsoft Security Blog
Microsoft Security Blog
J
Java Code Geeks
S
SegmentFault 最新的问题
Apple Machine Learning Research
Apple Machine Learning Research
N
Netflix TechBlog - Medium
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
博客园_首页
宝玉的分享
宝玉的分享
Google DeepMind News
Google DeepMind News
B
Blog RSS Feed
Hugging Face - Blog
Hugging Face - Blog
量子位
Blog — PlanetScale
Blog — PlanetScale
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
阮一峰的网络日志
阮一峰的网络日志
D
Docker
罗磊的独立博客
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
云风的 BLOG
云风的 BLOG
IT之家
IT之家
MyScale Blog
MyScale Blog
Microsoft Azure Blog
Microsoft Azure Blog

博客园 - 快乐家++

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); } } } } }