-
Aug 24th, 2009, 10:02 AM
#1
Thread Starter
Fanatic Member
Login onto a website
I'm working on a community application for displaying active members and more.
I know how to do this. (using webbrowser, getting html code )
But to see this section, you must log in.
It regards this website: http://productions.lostpirates.co.uk/
I tried everything, even html editing, but nothing helped.
How can I using vb .net (maybe html) login onto a website?
-
Aug 24th, 2009, 10:12 AM
#2
Re: Login onto a website
Hey,
You should be able to use the HttpWebRequest:
http://msdn.microsoft.com/en-us/libr...ebrequest.aspx
Which allows you to specify the Credentials that you want to use in the Request:
http://msdn.microsoft.com/en-us/libr...edentials.aspx
Hope that helps!!
Gary
-
Aug 24th, 2009, 10:13 AM
#3
Hyperactive Member
Re: Login onto a website
Use a program or add-on (such as Firebug or Tamper Data) to find the post data when you login to the site, then encode it using System.Text.Encoding.UTF8.GetBytes().
After doing so you can call the navigate method of the webbrowser control with the post data appended to the link.
This is just one way that I know about, I'm sure there are plenty more.
-
Aug 24th, 2009, 11:11 AM
#4
Junior Member
Re: Login onto a website
If you are using vb 06 then this might help > http://www.youtube.com/watch?v=ojN1QCP_c1g
-
Aug 24th, 2009, 11:15 AM
#5
Re: Login onto a website
Originally Posted by allstarsdied4me
Seeing as this is the .NET forum, I'd be surprised if he used VB6. Especially since he specifically mentions using VB.NET in the first post
-
Aug 24th, 2009, 11:15 AM
#6
Re: Login onto a website
Originally Posted by allstarsdied4me
If he is using VB 06, then he is posting in the wrong forum, and should ask for the thread to be removed.
Gary
-
Aug 25th, 2009, 10:59 AM
#7
Thread Starter
Fanatic Member
Re: Login onto a website
I managed to send a http request.
Code I use now:
Declarations:
Imports System.Net
Imports System.IO
Code:
Dim myWebReq As HttpWebRequest
Dim myWebResp As HttpWebResponse
Dim encoding As New System.Text.ASCIIEncoding()
Dim data() As Byte
Dim postData As String = ""
Dim sr As StreamReader
Dim sw As StreamWriter
postData += "txtUsername=bergerkiller"
postData += "&"
postData += "txtPassword=password"
Data = encoding.GetBytes(postData)
myWebReq = WebRequest.Create("http://productions.lostpirates.co.uk/")
myWebReq.Method = "POST"
myWebReq.ContentType = "application/x-www-form-urlencoded"
myWebReq.ContentLength = data.Length
Dim myStream As Stream = myWebReq.GetRequestStream()
myStream.Write(data, 0, data.Length)
myStream.Close()
myWebResp = myWebReq.GetResponse
sr = New StreamReader(myWebResp.GetResponseStream)
Dim strHTML As String = sr.ReadToEnd
sw = File.CreateText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\test.htm")
sw.WriteLine(strHTML)
sw.Close()
But I still can't log in. What should I do
Please help me out.
Last edited by bergerkiller; Aug 25th, 2009 at 11:37 AM.
-
Aug 25th, 2009, 12:36 PM
#8
Fanatic Member
Re: Login onto a website
myWebReq = WebRequest.Create("http://productions.lostpirates.co.uk/")
is that the exact address of the login page? I'm not familiar with webrequest, but logically it would seem that you would need to be on the exact page which holds the login screen.
-
Aug 25th, 2009, 12:52 PM
#9
Hyperactive Member
Re: Login onto a website
Here are the post parameters:
The post data would be something along the lines of:
Code:
Dim postData As String = "username=UsernameHere&user_password=MyPassword&op=login"
Encoding.ASCII.GetBytes(postData)
-
Aug 27th, 2009, 01:45 PM
#10
Thread Starter
Fanatic Member
Re: Login onto a website
Lol, how did you get that console?
Oh and, I can't use 'keep-alive", it gave me an error:
"Keep-Alive and Close can't be inherited with this property.
parameter name: value"
(translated from dutch)
Code:
Dim myWebReq As HttpWebRequest
Dim myWebResp As HttpWebResponse
Dim encoding As New System.Text.ASCIIEncoding()
Dim data() As Byte
Dim sr As StreamReader
Dim sw As StreamWriter
Dim postData As String = "username=Username&user_password=UserPass&op=login"
data = encoding.ASCII.GetBytes(postData)
myWebReq = WebRequest.Create("http://productions.lostpirates.co.uk/")
myWebReq.Accept = "Text/Html,application/xhtml+xml"
myWebReq.Method = "POST"
myWebReq.ContentLength = data.Length
myWebReq.UserAgent = "Mozilla/5.0"
myWebReq.Connection = "keep-alive"
myWebReq.KeepAlive = 300
myWebReq.Referer = "http://productions.lostpirates.co.uk/"
Dim myStream As Stream = myWebReq.GetRequestStream()
myStream.Write(data, 0, data.Length)
myStream.Close()
myWebResp = myWebReq.GetResponse
sr = New StreamReader(myWebResp.GetResponseStream)
Dim strHTML As String = sr.ReadToEnd
sw = File.CreateText(My.Computer.FileSystem.SpecialDirectories.Desktop & "\test.htm")
sw.WriteLine(strHTML)
sw.Close()
What should I do?
-
Aug 27th, 2009, 02:30 PM
#11
Hyperactive Member
Re: Login onto a website
I suppose you can just leave the keep alive property out and see if it sets a default value.
Oh, and that window is Tamper Data, an add-on for Firefox.
-
Aug 28th, 2009, 04:36 PM
#12
Thread Starter
Fanatic Member
Re: Login onto a website
Ah thanks. I downloaded and installed tamper data.
It seems to be a nice program.
I'll experiment a little with it. (especially postdata function)
-
Aug 28th, 2009, 05:43 PM
#13
Re: Login onto a website
Hey,
Another application that you may be interested in is ieHttpHeaders. It is an add-in for Internet Explorer, it simply let's you inspect the HTTP Headers that are being sent and received. It is a very simple interface, and let's you see what post data you would need to send along with the request.
Gary
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|