This is a discussion on "System.Net.WebException: The server committed a protocol violation. within the ASP and ASP.NET Programming forums, part of the Web Development category; Hi... i am getting the "System.Net.WebException: The server committed a protocol violation. Section=ResponseStatusLine" exception, when ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi... i am getting the "System.Net.WebException: The server committed a protocol violation. Section=ResponseStatusLine" exception, when i cantact a webservice using HttpWebRequest class... This is the code. Code:
HttpWebRequest webRequest = (HttpWebRequest)System.Net.WebRequest.Create(url);
webRequest.Credentials = System.Net.CredentialCache.DefaultCredentials;
webRequest.Accept = "text/xml";
webRequest.AllowAutoRedirect = true;
HttpWebResponse webResponse=null;
Stream s = null;
try
{
webResponse = (HttpWebResponse)webRequest.GetResponse();
s = webResponse.GetResponseStream();
}
catch
{
} Iam getting error in the try block... thnx in advance... |
| Sponsored Links |
| |||
| Hi, One of the issues involving XML-RPC.NET that turns up fairly frequently is when the library throws an instance of System.Net.WebException with the message ""The server committed a protocol violation". This usually occurs because from .NET 1.1 SP1 onwards the parsing of HTTP responses became much more strict, as a security measure to prevent attacks which exploit malformed HTTP status lines and headers. The strict behaviour can be switched off via the application config file.
__________________ Sathish Kumar.R ![]() Knowledge is meant to SHARE |
| |||
| Hi , Here is the xml code section that you need <?xml version ="1.0"?> <configuration> <system.net> <settings> <httpWebRequest useUnsafeHeaderParsing="true" /> </settings> </system.net> </configuration>
__________________ Sathish Kumar.R ![]() Knowledge is meant to SHARE |
| |||
| Hi Sathish... I found one more way to achive this... From .NET 2.0 this behaviour can be configured programmatically using the HttpWebRequestElement useUnsafeHeaderParsing property. At first when I read about this I assumed it was a property that can be set dynamically at runtime, for example in the same way as the HttpWebRequest KeepAlive property. But in fact its used in the new 2.0 configuration infrastructure to set the value in the config file (although once you do this the new value applies to the current running application as well as any apps launched afterwards. The new configuration infrastructure is pretty complex but this code seems to work ok: Code: Configuration config = ConfigurationManager.OpenExeConfiguration( ConfigurationUserLevel.None); SettingsSection section = (SettingsSection)config.GetSection( "system.net/settings"); section.HttpWebRequest.UseUnsafeHeaderParsing = false; config.Save(); thnks.. |
| |||
| Hi, Finally, I found the code below in a post on the .NET Framework Networking and Communication forum. This uses reflection to set the private field useUnsafeHeaderParsing to true and as a result may not be suitable in all scenarios where the relevant code access security permission is not available. (Note: add System.Configuration.dll as a reference to your project.) Code: public static bool SetAllowUnsafeHeaderParsing()
{
//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, true);
return true;
}
}
}
}
return false;
}
__________________ Sathish Kumar.R ![]() Knowledge is meant to SHARE |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| What is the difference between "using System.Data;" and directly adding the refer | KiruthikaSambandam | ASP and ASP.NET Programming | 1 | 11-15-2007 01:33 AM |
| Anybody explain about "Common Type System" (CTS)? | H2o | ASP and ASP.NET Programming | 5 | 08-09-2007 08:02 AM |
| What is the difference between "using System.Data;" and directly adding the reference | H2o | ASP and ASP.NET Programming | 1 | 07-24-2007 03:33 AM |
| I get the error message "Unable to start debugging on the web server..." when I debug | oxygen | ASP and ASP.NET Programming | 1 | 07-20-2007 04:50 AM |
| Don't Use "SP_" Prefix for Stored Procedure Name in SQL Server 200X | Gopisoft | Database Support | 0 | 07-16-2007 04:01 AM |