WebRequest, (400) Bad Request. RRS feed

  • Question

  • User1076264835 posted

    Hai guys,

    I create a windows application using vb.net and put the httpwebrequest in the timer which is have a function for checking a time.

    For the first request its working fine but when it continue to the second request I got an error The remote server returned an error: (400) Bad Request.

    I already close GetResponseStream, dataStream and reader. I also used keepAlive = False

    The request server is using HTTP version 1.0.

    Dim request As HttpWebRequest = CType(HttpWebRequest.Create(URLStr), HttpWebRequest)
    Using response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)
        Dim dataStream As Stream = response.GetResponseStream()
        Dim reader As New StreamReader(dataStream)
        Dim MTstatus As String = reader.ReadToEnd()
        If status = "100" Then
           status = "Ok"
        End If
    End Using

    Tuesday, June 18, 2013 3:48 AM


  • User-861818263 posted

    refrence : http://wiki.asp.net/page.aspx/285/httpwebrequest/rev/8

    If Not (IsPostBack) Then
            Dim fr As System.Net.HttpWebRequest
            Dim targetURI As New Uri("http://weblogs.asp.net/farazshahkhan")
            fr = DirectCast(System.Net.HttpWebRequest.Create(targetURI), System.Net.HttpWebRequest)
            'In the above code http://weblogs.asp.net/farazshahkhan is used as an example
            'it can be a different domain with a different filename and extension
            If (fr.GetResponse().ContentLength > 0) Then
                Dim str As New System.IO.StreamReader(fr.GetResponse().GetResponseStream())
            End If
        Catch ex As System.Net.WebException
            Response.Write("File does not exist.")
        End Try
    End If

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, June 18, 2013 4:05 AM