Search

HttpWebRequest.GetResponse throws a WebException (same code in 1.1 works OK) by orbit1

Closed
as By Design Help for as By Design

7
Sign in to vote
0
Sign in to vote
Sign in
to vote
Type: Bug
ID: 94225
Opened: 7/10/2004 4:06:04 PM
Access Restriction: Public
0
Workaround(s)
2
User(s) can reproduce this bug
This code:

Dim Url AS String = "http://www.amazon.com"
Dim req1 As HttpWebRequest
req1.CookieContainer = New CookieContainer
req1.AllowAutoRedirect = True
Dim res1 As HttpWebResponse
req1 = CType(HttpWebRequest.Create(Url), HttpWebRequest)
res1 = CType(req1.GetResponse(), HttpWebResponse)

works in 1.1 but throws this Exception in 2.0:

{System.Net.WebException}
    [System.Net.WebException]: {System.Net.WebException}
    _className: Nothing
    _COMPlusExceptionCode: -532459699
    _data: Nothing
    _dynamicMethods: Nothing
    _exceptionMethod: Nothing
    _exceptionMethodString: Nothing
    _helpURL: Nothing
    _HResult: -2146233079
    _innerException: Nothing
    _message: "The server committed a protocol violation"
    _remoteStackIndex: 0
    _remoteStackTraceString: Nothing
    _source: Nothing
    _stackTrace: {System.Array}
    _stackTraceString: Nothing
    _xcode: -532459699
    _xptrs: 0
    Data: {System.Collections.ListDictionaryInternal}
    HelpLink: Nothing
    HResult: -2146233079
    InnerException: Nothing
    IsTransient: False
    Message: "The server committed a protocol violation"
    Source: "System"
    StackTrace: " at System.Net.HttpWebRequest.CheckFinalStatus(Boolean mustThrow)
at System.Net.HttpWebRequest.GetResponse()
at bs.Details.GetHTMLFromUrl(String URL) in C:\Net\Source\ORbitter2\bsAmazon\Details.vb:line 321"
    TargetSite: {System.Reflection.RuntimeMethodInfo}
Details (expand)
Product Language
English
Version
Visual Studio 2005 Beta 1
Category
Data
Subcategory
 
Operating System
Windows XP Professional
Steps to Reproduce
Try it
Actual Results
What do you want me to write here?
Expected Results
Code should work as in Version 1.1
File Attachments
1 attachments
Sign in to post a comment.
Posted by Microsoft on 7/27/2004 at 6:05 PM
Thank you for submitting this to us. We will investigate and keep you informed.

The System.Net Team
Posted by Microsoft on 7/28/2004 at 7:05 PM
After investigating this, we have concluded this is by design.

Due to increased security requirements, .NET 1.1 SP1 will now only accept HTTP responses that are 100% compliant with
the HTTP RFC specification (see RFC 2616). The servers listed below return almost, but not quite compliant HTTP
responses. For example, when I tried your code against www.amazon.com, the response does not appear to contain a description of the status code, which is probably a protocol violation. These violations will generate server protocol violation exceptions.

As a work around, you can configure your application to accept headers that are not perfectly formed:

- Open the *.exe.config for your application, or the configuration file for your entire .NET system.
- Look for the following XML tags in the configuration:

     <system.net>
    <settings>
        <httpWebRequest useUnsafeHeaderParsing = "true" />
    </settings>
     </system.net>

- If the system.net tag is not there, then add it.
- Add the setting to allow unsafe headers as shown above.

I hope this helps.