zoukankan      html  css  js  c++  java
  • 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); } } } } }
  • 相关阅读:
    配置Nginx和Apache允许指定域名CORS跨域访问
    当遇到npm ERR! Unexpected end of JSON input while parsing near……时的解决办法
    基于thinkphp开发的项目部署到由宝塔面板创建的LNMP服务器上解决路径出错问题
    在ThinkPHP框架(5.0.24)下引入Ueditor并实现向七牛云对象存储上传图片同时将图片信息保存到MySQL数据库,同时实现lazyload懒加载
    为Sublime Text 3设置优雅的字体
    windows7x64系统中配置mysql5.7.17为本地开发环境(win2008类似)
    SQL Server实现数据的递归查询
    在.net程序中使用System.Net.Mail来发送邮件
    在 Ubuntu 13.10 中搭建Java开发环境
    Windows 系统下载安装 ZooKeeper
  • 原文地址:https://www.cnblogs.com/chengulv/p/6146533.html
Copyright © 2011-2022 走看看