Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

A problem with HttpWebResponse object to get HTTP Response

Status
Not open for further replies.

Plato2

Programmer
Dec 6, 2002
192
US
I'm trying to get an HTML content of a remote page. This page accepts Login and Password. I'm trying to pass login and password but HTTP content get returned is not correct.
Any idea why?
Thanks in advance

Dim lcUrl As String = " Dim UserName, UserPwd As String
UserName = "user_name"
UserPwd = "password"
Dim loHttp As HttpWebRequest = WebRequest.Create(lcUrl)
loHttp.AllowAutoRedirect = True
'post data
Dim lcPostData As String = "username=" + HttpUtility.UrlEncode(UserName) + "&password=" + HttpUtility.UrlEncode(UserPwd)
loHttp.Method = "POST"
loHttp.ContentLength = lcPostData.Length

Dim lbPostBuffer As Byte() = System.Text.Encoding.GetEncoding(1252).GetBytes(lcPostData)

loHttp.ContentLength = lbPostBuffer.Length
Dim loPostData As Stream = loHttp.GetRequestStream()
loPostData.Write(lbPostBuffer, 0, lbPostBuffer.Length)
loPostData.Close()
Dim loWebResponse As HttpWebResponse = loHttp.GetResponse()
Dim enc As Encoding = System.Text.Encoding.GetEncoding(1252)
Dim loResponseStream As StreamReader = New StreamReader(loWebResponse.GetResponseStream(), enc)
Dim lcHtml As String = loResponseStream.ReadToEnd()
Response.Write(lcHtml)

loWebResponse.Close()
loResponseStream.Close()
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top