Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This LINQPad query works fine, dumping the HTML provided by my web server's "Not Found" error web page:</p> <pre><code>Dim rq = System.Net.WebRequest.Create(New Uri("http://localhost/test")) Try Dim rs = rq.GetResponse rs.Dump Catch Ex As System.Net.WebException Dim rs = Ex.Response Call (New StreamReader(rs.GetResponseStream)).ReadToEnd.Dump End Try </code></pre> <p>FYI Your code works for me, except the presumed typo re <code>HttpWebResponse.StatusDescription</code> (and commenting out "unrelated stuff"), again as a LINQPad query (in .NET 4.0):</p> <pre><code>Dim request = WebRequest.Create("http://localhost/test") Dim myStreamReader As StreamReader Dim SendStatus As Integer = -1 Dim statusCode As HttpStatusCode Dim ResponseText As String Try Dim myWebResponse = CType(request.GetResponse(), HttpWebResponse) myStreamReader = New StreamReader(myWebResponse.GetResponseStream()) ResponseText = myStreamReader.ReadToEnd If myWebResponse.StatusCode = HttpStatusCode.Accepted Or myWebResponse.StatusCode = 200 Then 'SendResult = True 'Sent SendStatus = 1 'message sent successfully 'Try ' Integer.TryParse(myWebResponse.Headers("Number-Of-MT-PDU"), num_MT_PDU) 'Catch ex As Exception 'End Try Else SendStatus = 2 'message processed but not sent successfully End If Catch e As WebException If (e.Status = WebExceptionStatus.ProtocolError) Then Dim response As WebResponse = e.Response Using (response) Dim httpResponse As HttpWebResponse = CType(response, HttpWebResponse) statusCode = httpResponse.StatusCode Try myStreamReader = New StreamReader(response.GetResponseStream()) Using (myStreamReader) ResponseText = myStreamReader.ReadToEnd &amp; "Status Description = " &amp; httpResponse.StatusDescription ' HttpWebResponse.StatusDescription End Using Catch ex As Exception 'Logger.LogError(Me, ex) ex.Dump("Exception") End Try End Using End If End Try ResponseText.Dump("ResponseText") </code></pre> <p>I have also confirmed the above code (with the inferred <code>As</code> clauses added and converting the <code>.Dump</code> calls to <code>Console.WriteLine</code>) works in .NET 2.0 with VB8.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload