Login through HttpWebRequest?
-
I actually want to login to a web server on Local Area Network through HttpWebRequest Class, I am using the following code but can't seems to work...
Dim wr As HttpWebRequest Dim wrs As HttpWebResponse wr = CType(WebRequest.Create("http://192.168.2.142/"), HttpWebRequest) wr.Method = "POST" Dim postData = "frmUserName=myUserName...&frmUserPass=myPassword..." wr.ContentLength = postData.Length wr.ContentType = "application/x-www-form-urlencoded" wr.AllowAutoRedirect = False Dim buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(postData) Dim dataStrm As Stream = wr.GetRequestStream() dataStrm.Write(buffer, 0, buffer.Length) dataStrm.Close() Try wrs = wr.GetResponse Dim sr As New StreamReader(wrs.GetResponseStream) Me.rtxtData.Text = sr.ReadToEnd.ToString() sr.Close() Catch ex As Exception MsgBox(ex.ToString()) End Try
Thanks in advance !
AliAmjad(MCP) First make it Run THEN make it Run Fast!
-
I actually want to login to a web server on Local Area Network through HttpWebRequest Class, I am using the following code but can't seems to work...
Dim wr As HttpWebRequest Dim wrs As HttpWebResponse wr = CType(WebRequest.Create("http://192.168.2.142/"), HttpWebRequest) wr.Method = "POST" Dim postData = "frmUserName=myUserName...&frmUserPass=myPassword..." wr.ContentLength = postData.Length wr.ContentType = "application/x-www-form-urlencoded" wr.AllowAutoRedirect = False Dim buffer() As Byte = System.Text.Encoding.ASCII.GetBytes(postData) Dim dataStrm As Stream = wr.GetRequestStream() dataStrm.Write(buffer, 0, buffer.Length) dataStrm.Close() Try wrs = wr.GetResponse Dim sr As New StreamReader(wrs.GetResponseStream) Me.rtxtData.Text = sr.ReadToEnd.ToString() sr.Close() Catch ex As Exception MsgBox(ex.ToString()) End Try
Thanks in advance !
AliAmjad(MCP) First make it Run THEN make it Run Fast!
AliAmjad wrote:
Dim postData = "frmUserName=myUserName...&frmUserPass=myPassword..."
You're joking, right?? This website requires you to send the username and password IN PLAIN TEXT in the URL string?? So much for security... Without knowing what the website requires, or how you login to it, it's impossible to tell you how to fix this. Everything depends on how the website works.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
AliAmjad wrote:
Dim postData = "frmUserName=myUserName...&frmUserPass=myPassword..."
You're joking, right?? This website requires you to send the username and password IN PLAIN TEXT in the URL string?? So much for security... Without knowing what the website requires, or how you login to it, it's impossible to tell you how to fix this. Everything depends on how the website works.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008:-D Actually this is the only line in code i don't understand how to arrange the post data, I saw some examples but can't seems to work as far as website goes it's an Easy File Sharing web server http://www.sharing-file.com/ on LAN, read their whole site but didn't find the solution i think they receive username and password in plain text. But again I have made a login form in ASP.NET and then tried to login there but again can't! what's the problem is there something wrong with my code???
AliAmjad(MCP) First make it Run THEN make it Run Fast!
-
:-D Actually this is the only line in code i don't understand how to arrange the post data, I saw some examples but can't seems to work as far as website goes it's an Easy File Sharing web server http://www.sharing-file.com/ on LAN, read their whole site but didn't find the solution i think they receive username and password in plain text. But again I have made a login form in ASP.NET and then tried to login there but again can't! what's the problem is there something wrong with my code???
AliAmjad(MCP) First make it Run THEN make it Run Fast!
How does the site ask for a username and password?? Is it in a web page?? Is it in a small popup window?? How??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
How does the site ask for a username and password?? Is it in a web page?? Is it in a small popup window?? How??
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
here is the screen shot and its not a secure edition too: http://yehpal.googlepages.com/login.JPG[^]
AliAmjad(MCP) First make it Run THEN make it Run Fast!
OK. You can't take the approach you're using to fill in the username and password. You have to write code that gets this page, then finds the username and passwords HTML input boxes in the form, fill them in, then "click" on the Login! button to submit the filled in page back to the webserver.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
OK. You can't take the approach you're using to fill in the username and password. You have to write code that gets this page, then finds the username and passwords HTML input boxes in the form, fill them in, then "click" on the Login! button to submit the filled in page back to the webserver.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Thanks for putting me in a right direction but can you please give me a hint which class i should use to fill the input boxes and to invoke the click event of Login button.
AliAmjad(MCP) First make it Run THEN make it Run Fast!
Sorry, but you use a Web Browser control to do this.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008 -
Sorry, but you use a Web Browser control to do this.
A guide to posting questions on CodeProject[^]
Dave Kreskowiak Microsoft MVP Visual Developer - Visual Basic
2006, 2007, 2008