HttpWebRequest Error The server submitted a protocol violation. Section=responseheader DETAIL=CR back must be LF

Source: Internet
Author: User

The server submitted a protocol violation. Section=responseheader DETAIL=CR back must be LF

The server committed a protocol violation. Section=responseheader DETAIL=CR must is followed by LF

The main meaning is that Microsoft does not tolerate a server response that does not conform to the provisions of RFC 822 that Httpheader must end with CRLF.

One solution is to add a application.config or Web. config file

<system.net>

<settings>


</settings>

</system.net>

Allow the system to tolerate (tolerant) hearder information that ends in CR or LF only

Using System.Reflection;


BOOLgetallowunsafeheaderparsing () {//Get The assembly that contains the internal classAssembly anetassembly = assembly.getassembly (typeof(System.Net.Configuration.SettingsSection)); if(anetassembly! =NULL) { //Use the assembly in order to get the internal type for//The internal classType 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 would create it for us. ObjectAninstance = 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 notFieldInfo auseunsafeheaderparsing =Asettingstype.getfield ("useunsafeheaderparsing", BindingFlags.NonPublic|bindingflags.instance); if(Auseunsafeheaderparsing! =NULL) return(BOOL) Auseunsafeheaderparsing.getvalue (aninstance); } } } return false; } voidSetallowunsafeheaderparsing (BOOLval) { //Get The assembly that contains the internal classAssembly anetassembly = assembly.getassembly (typeof(System.Net.Configuration.SettingsSection)); if(anetassembly! =NULL) { //Use the assembly in order to get the internal type for//The internal classType 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 would create it for us. ObjectAninstance = 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 notFieldInfo auseunsafeheaderparsing =Asettingstype.getfield ("useunsafeheaderparsing", BindingFlags.NonPublic|bindingflags.instance); if(Auseunsafeheaderparsing! =NULL) {Auseunsafeheaderparsing.setvalue (Aninstance, Val); } } } } }

HttpWebRequest Error The server submitted a protocol violation. Section=responseheader DETAIL=CR back must be LF

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.