WebBrowser control connects but httpRequest does not! Why is it different?

Using VB.Net

I have a form, user, password, url. A multiline tex box to show html source, a web browser control to show html ( mainly to prove connection is possible.)

I try to requst a page from my webserver which has basic authentication set, user Test,  pwd Test.

The webserver is onboard a network input output module

When the browser connects a dialog pops up. i enter the credentials and click ok. The web server sends the correct page.

When using the request method i get disconnected during the GetResponse. What is the web browser control doing that i am not Code included:

If the webbrowser can do it then surely i can

web server: ( not a static ip, but shold be alright for a few days!)

http://88.144.5.146

user: test

pwd: test

 

Imports system.net
Imports System.IO;

Public Class frmgetHTTP
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnGo.Click
tbResults.Text = getHTTP(tbURL.Text) ' disconnects during GetResponse
WebBrowser1.Navigate(tbURL.Text) ' works, dialog shows
End Sub

Private Function getHTTP(ByVal url As String)
Dim httpRequest As HttpWebRequest
Dim httpResponse As HttpWebResponse
Dim bodytext As String = ""
Dim responseStream As Stream
Dim bytes As Int32
Dim RecvBytes(Byte.MaxValue) As Byte
Try
httpRequest = CType(WebRequest.Create(url), HttpWebRequest)
httpRequest.Credentials = New NetworkCredential(tbUser.Text, tbPWD.Text)
httpResponse = CType(httpRequest.GetResponse, HttpWebResponse)
responseStream = httpResponse.GetResponseStream()
Do While (True)
   bytes = responseStream.Read(RecvBytes, 0, RecvBytes.Length)
   If bytes <= 0 Then Exit Do
   bodytext += System.Text.Encoding.UTF8.GetString(RecvBytes, 0, bytes)
Loop

Catch webExcp As WebException
 MessageBox.Show(webExcp.Message)
Catch ex As Exception

End Try

Return bodytext

End Function

End Class



Answer this question

WebBrowser control connects but httpRequest does not! Why is it different?

  • Naimisar

    The code looks fine. The IP appears to be invalid as I could not reach it to test.

  • Dayan_07

    hi,

    i don't know what the Credentials does i have tried it b4 and it didn't work but i send the variables in teh url like www.site.com/long.asp username=name&password=password this works for me, and i set a cookiesContainer to the request then i use this contain in all the future request

    hope this helps



  • WebBrowser control connects but httpRequest does not! Why is it different?