HttpWebRequest出错 服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF
服务器提交了协议冲突. 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的更多相关文章
- 关于 服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF 错误
用WebClient 去下载数据时发现有服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF错误,解决办法 1.在app.config种添加 we ...
- WebRequest请求错误(服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF)
WebRequest请求错误(服务器提交了协议冲突. Section=ResponseHeader Detail=CR 后面必须是 LF)解决办法,天津config文件,增加一个配置如下 <?x ...
- 服务器提交了协议冲突. Section=ResponseHeader Detail=CR...的解决方案总结
今天在HttpWebRequest发送一个网页请求的时候,HttpWebResponse返回了一个奇怪的错误信息: 这个Http协议请求类可是微软封装的,我使用的流程可是中规中矩,不可能是我写错代码, ...
- httpwebrequest 服务器提交了协议冲突. section=responsestatusline
调用接口的时候,包: httpwebrequest 服务器提交了协议冲突. section=responsestatusline 解决方案: req.KeepAlive = false; req.Al ...
- 解决WebService/WCF调用时报错"服务器提交了协议冲突. Section=ResponseStatusLine"问题
今天更新了一个网站,新增了一个页面,调用WebService,在测试环境好好的,部署到正式环境后就莫名报错: 服务器提交了协议冲突. Section=ResponseStatusLine 网上查了好多 ...
- c# winform 服务器提交了协议冲突. Section=ResponseStatusLine
[转] 最近在用.net写一个网络蜘蛛,发现对有的网站用HttpWebrequest抓取网页的时候会报错,捕获异常提示:"服务器提交了协议冲突 Section=ResponseStatusL ...
- 关于“服务器提交了协议冲突. Section=ResponseStatusLine"问题
你的问题的原因是这样的,ASP.Net 2.0 增强了安全性,对一些有危害的http 头进行了判断,比如url中有空格的情况,以帮助网站提高网络攻击的防御能力.如果你的http头中有一些ASP.NET ...
- C#调取接口时报错:服务器提交了协议冲突. Section=ResponseStatusLine
private Dictionary<string, Object> GetLocation(string imei) { #region===代码=== string serviceAd ...
- 服务器提交了协议冲突。Section=ResponseHeader Detail=标头名称无效
服务器提交了协议冲突.Section=ResponseHeader Detail=CR 后面必须是LF. 微软没有容忍不符合RFC 822中的httpHeader必须以CRLF结束的规定的服务器响应所 ...
随机推荐
- Three.js typescript definitely typed 文件
最近学习three.js,想用typescript编写代码,去http://definitelytyped.org/找了一圈没有发现three.js的definitely typed文件. 好吧,花了 ...
- SharePoint 2013 中的 PowerPoint Automation Services
简介 许多大型和小型企业都将其 Microsoft SharePoint Server 库用作 Microsoft PowerPoint 演示文稿的存储库.所有这些企业在 ...
- 关于ASPXGridview的双击事件弹出 【转】
在网上找了好长时间,关于ASPXGridview的双击事件弹出ASPxPopupControl,也没有找到适合自己的代码,这里将自己编写出来的代码与大家分享一下 希望我的代码能够对你有所帮助. 直接上 ...
- C#的New关键字的几种用法
一.在C#中,new这个关键字使用频率非常高,主要有3个功能: a) 作为运算符用来创建一个对象和调用构造函数. b) 作为修饰符. c) 用于在泛型声明中约束可能用作类型参 ...
- 最大流模版 pascal
//最大流模版 ; maxm=; ..maxn] of integer; end; var n,m,max:longint; r:..maxn,..maxn] of longint; g:..maxn ...
- jquery+php+mysql实现Ajax省市县三级联动
1.第一步建立一个html页面的,放置省.市.县三个select选择框,代码如下: <!DOCTYPE html> <html> <head> <title& ...
- c++类的嵌套(1)
在一个类的内部定义另一个类或结构体,我们称之为嵌套类(nested class),或者嵌套类型.之所以引入这样一个嵌套类,往往是因为外围类需要使用嵌套类对象作为底层实现,并且该嵌套类只用于外围类的实现 ...
- C# 类:类型 , 数学:类型
类(类型): //.Length:获取字符串的长度,返回int型 //.Trim去除字符串前后的空格 / ...
- ZendStudio13 PHP调试环境快速配置
1.百度ZendStudio13,汉化,破解,注册: 2.安装国产Apache+MySql一键安装环境phpStudy,方便快速 http://www.phpstudy.net/a.php/208. ...
- HBase学习笔记-HBase性能研究(1)
使用Java API与HBase集群交互时,需要构建HTable对象,使用该对象提供的方法来进行插入/删除/查询等操作.要创建HTable对象,首先要创建一个带有HBase集群信息的配置对象Confi ...