Home Dashboard Directory Help
Search

System.Net.WebClient does not return data when receiving an HTTP 500 status by Ronald Rink


Status: 

Active


1
0
Sign in
to vote
Type: Bug
ID: 786972
Opened: 5/15/2013 7:05:23 AM
Access Restriction: Public
1
Workaround(s)
view
0
User(s) can reproduce this bug

Description

When using System.Net.WebClient and the Server responds with an HTTP 500 Status code the WebClient throws an exception and does not return the data sent by the server to the caller.
This issue always occurs at least until .NET v4.0.

As a side note: this behaviour actually violates the SHOULD recommendation of RFC 2616 #10.5.
Details
Sign in to post a comment.
Sign in to post a workaround.
Posted by Ronald Rink on 7/26/2013 at 9:07 AM
You can actually get the server response when accessing the InnerException.Response property:

$HttpWebResponse = $_.Exception.InnerException.Response;
if($HttpWebResponse -is [System.Net.HttpWebResponse]) {
    $sr = New-Object System.IO.StreamReader($HttpWebResponse.GetResponseStream(), $true);
    $Content = $sr.ReadToEnd();
} # if