Urgent:The remote server returned an error: (400) Bad Request.

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I got a error this line "request.GetResponse()"

Error Message is :The remote server returned an error: (400) Bad Request.

please do helpful? See Below code

Public Shared Sub RedirectHTTPAuthExample(ByVal username As [String], ByVal password As [String])

Dim creds As New NetworkCredential(username, password, "http://clerks.jetlinetravel.info/xml/booking-details")
Dim credCache As New CredentialCache()
Cached credentials can only be used when requested by
specific URLs and authorization schemes
credCache.Add(New Uri("http://clerks.jetlinetravel.info/xml/booking-details?quoteRef=HD5109999709"), "Basic", creds)

Dim request As WebRequest = WebRequest.Create("http://clerks.jetlinetravel.info/xml/booking-details?quoteRef=HD5109999709")
Must be a cache, basic credentials are cleared on redirect
request.Credentials = credCache
request.PreAuthenticate = True
request.Method = WebRequestMethods.Http.Post
request.ContentType = "application/x-www-form-urlencoded"
request.ContentLength = 0

More efficient, but optional
Dim response As WebResponse = request.GetResponse()
Dim responseStreamReader As New StreamReader(response.GetResponseStream())
Dim result As [String] = responseStreamReader.ReadToEnd()
responseStreamReader.Close()
Console.WriteLine(result)
End Sub

View the full article
 
Back
Top