HTTP 500 error using Httpwebrequest

Asked

Viewed 1,060 times

4

I come here to ask for help regarding Httpwebrequest requests. I need to get the return html of an HTTP 500 (HTTP/1.1 500 Internal Server Error) error. Could someone tell me how it could be done? Below is an example of an Httpwebrequest request that is returning the error

 PostData &= "&" & System.Web.HttpUtility.UrlEncode("btnOK", System.Text.Encoding.UTF8) & "=" & System.Web.HttpUtility.UrlEncode("OK", System.Text.Encoding.UTF8)

            url = "www.google.com"
            req = HttpWebRequest.Create(url)
            req.Method = "POST"
            req.Headers.Add(HttpRequestHeader.AcceptLanguage, "pt-BR")
            req.Headers.Add(HttpRequestHeader.Cookie, cookie)
            req.Headers.Add(HttpRequestHeader.Pragma, "no-cache")
            req.Referer = "www.google.com"
            req.UserAgent = "Mozilla/5.0 (Windows NT 6.3; WOW64; Trident/7.0; rv:11.0) like Gecko"
            req.AutomaticDecompression = DecompressionMethods.GZip
            req.ContentType = "application/x-www-form-urlencoded"
            req.ContentLength = PostData.Length

        End If

    End If

    Try

        Dim swRequestWriter As StreamWriter = New StreamWriter(req.GetRequestStream())

        swRequestWriter.Write(PostData)
        swRequestWriter.Close()

        Dim srResponseReader As New StreamReader(req.GetResponse().GetResponseStream(), System.Text.Encoding.Default)

        Html = srResponseReader.ReadToEnd()

        swRequestWriter.Close()

        srResponseReader.Close()


    Catch ex As Exception

    End Try

1 answer

4


Browser other questions tagged

You are not signed in. Login or sign up in order to post.