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结束的规定的服务器响应所 ...
随机推荐
- Android深度探索--HAL与驱动开发----第六章读书笔记
Linux驱动程序与其他类型的Linux程序一样拥有自己的规则,下面给出一个编写基本的Linux驱动的一般步骤: (1)建立Linux驱动的骨架(装载和卸载Linux驱动): (2)注册和注销设备文件 ...
- 在oracle中通过connect by prior来实现递归查询!
注明:该文章为引用别人的文章,链接为:http://blog.csdn.net/apicescn/article/details/1510922 ,本人记录下来只是为了方便查看 原文: connect ...
- Web测试中常见分享问题
Web测试中,由于开发通常指注重完成H5页面的逻辑功能,对各种系统.浏览器等考虑不周,同时Android端各类机型碎片化,容易产生兼容性问题,这其中以分享类型为最. 本文简单分析总结一些测试 ...
- oracle xmltype导入并解析Excel数据 (五)中间表数据入库
此处给出例子,具体根据业务需求 create or replace procedure P_CART_Sheet1(p_id in NUMBER) is--车辆管理功能v_str varchar2(4 ...
- HDU 5512
http://acm.hdu.edu.cn/showproblem.php?pid=5512 gcd(a,b)的位置都是可以选的,之后判断一下奇偶 #include <iostream> ...
- Unity3d游戏场景优化杂谈(2)
动态实时灯光相比静态灯光,非常耗费资源.所以除了能动的角色和物体(比如可以被打的到处乱飞的油桶)静态的地形和建筑,通通使用Lightmap. 强大的Unity内置了一个强大的光照图烘焙工具Beast, ...
- 联合(union)类型有哪些使用场景
2013-08-22 - 18:17:50 by Gold_Lion 今天突然碰到“联合”这个数据类型了,平时用的不多,实在也想不出来它到底能帮我干嘛?于是google了一下,终于有一个是利用联合( ...
- Day23_IO第五天
1.递归求5的阶乘 package com.heima.chario; public class Demo8_Digui { /** * @param args * 递归:方法自己调用自己 * 5! ...
- C++类成员布局
在C++中对象的内存布局与类成员声明的顺序一致,静态成员放在数据区(Data Section)而非对象内存中,若多个类静态成员名称相同,C++则按照name mangling技术进行重命名保证名称的唯 ...
- The Docker学习记录[Doing]
微服务 & Docker 译文:使用Java构建微服务 原文:Building Microservices With Java [编者的话]本文翻译自Dzone Guide to the Ja ...