"loggin in" to a site?
"loggin in" to a site?
"loggin in" to a site?
"loggin in" to a site?
"loggin in" to a site?
"loggin in" to a site? "loggin in" to a site? "loggin in" to a site? "loggin in" to a site? "loggin in" to a site? "loggin in" to a site? "loggin in" to a site? "loggin in" to a site?
"loggin in" to a site? "loggin in" to a site?
"loggin in" to a site?
Go Back  Xtreme Visual Basic Talk > > > "loggin in" to a site?


Reply
 
Thread Tools Display Modes
  #1  
Old 09-04-2007, 10:37 PM
py343 py343 is offline
Centurion
 
Join Date: Aug 2007
Posts: 120
Default "loggin in" to a site?


How can I make an app that logs into a side (such as a webmail site) without using a browser? I know you can receive information, but is there a way to "send" information to a website (into the forms) without a browser?

I've decided I want to use winsock HTTP POST/GET.

Last edited by py343; 09-04-2007 at 11:04 PM.
Reply With Quote
  #2  
Old 09-05-2007, 06:57 AM
shaul_ahuva"loggin in" to a site? shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

You'll probably want to use the HttpWebRequest and HttpWebReponse classes in the System.Netnamespace.

As a sidenote, many sites use a cookie to persist authentication information so you'll want to ensure you account for cookies (see the .CookieContainer property for more information).
Reply With Quote
  #3  
Old 09-05-2007, 12:42 PM
py343 py343 is offline
Centurion
 
Join Date: Aug 2007
Posts: 120
Default

Quote:
Originally Posted by shaul_ahuva View Post
You'll probably want to use the HttpWebRequest and HttpWebReponse classes in the System.Netnamespace.

As a sidenote, many sites use a cookie to persist authentication information so you'll want to ensure you account for cookies (see the .CookieContainer property for more information).
I managed to set some attributes, but when I set headers (like the username,whatevertheusernameis and the password), they don't appear to be recognized/accepted/entered.
Reply With Quote
  #4  
Old 09-05-2007, 08:53 PM
shaul_ahuva"loggin in" to a site? shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Are you sure the username and password should be in the headers of the request? I would expect these in either the url (GET) or body (POST) of the request as name=value pairs separated by ampersands.
Reply With Quote
  #5  
Old 09-07-2007, 12:16 AM
py343 py343 is offline
Centurion
 
Join Date: Aug 2007
Posts: 120
Default

Quote:
Originally Posted by shaul_ahuva View Post
Are you sure the username and password should be in the headers of the request? I would expect these in either the url (GET) or body (POST) of the request as name=value pairs separated by ampersands.
Can you give an example of how to login, say, for hotmail.
Reply With Quote
  #6  
Old 09-07-2007, 08:46 AM
shaul_ahuva"loggin in" to a site? shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

The basic process would be:
  1. Create a HttpWebRequest for the "login" url using the HttpWebRequest.Create method - the "login" url can be determined by looking at the "action" attribute of the login form. For example, the true "login" url of live.com is "http://live.com/ppsecure/post.srf".
  2. Create a string containing the required form values and write it to the request stream:
    Code:
    Dim formValues As String = "login=your username&passwd=your password"
    You can obtain a reference to the request stream via the HttpWebRequest.GetRequestStream method.
  3. Send the request by calling the HttpWebRequest.GetResponse() method. Before sending the request, you'll need to set the Method, CookieContainer, ContentType, and ContentLength properties to appropriate values.
  4. Save the cookies contained in the HttpWebResponse.Cookies property. These cookies will need to be sent with next request.

I would recommend getting an application that sniffs HTTP headers for you (such as ieHTTPheaders) to see what the browser is sending and receiving - this will help you figure out what to do in your application.

All of that being said, it would probably be much easier to use the WebBrowser control to navigate a site since there's a whole host of issues you'll need to address if you continue on this path - active scripting being the largest and most difficult of them. Is there a specific reason you don't want to use the WebBrowser control?

Finally, live.com is a bit different from the "normal" site as they use Passport for authentication. Since the basic process above doesn't work with live.com but does work with XVBT, I think there's other things that need to be sent along with the user's credentials.

Additionally,
Reply With Quote
  #7  
Old 09-07-2007, 07:36 PM
py343 py343 is offline
Centurion
 
Join Date: Aug 2007
Posts: 120
Default

Quote:
Originally Posted by shaul_ahuva View Post
The basic process would be:
  1. Create a HttpWebRequest for the "login" url using the HttpWebRequest.Create method - the "login" url can be determined by looking at the "action" attribute of the login form. For example, the true "login" url of live.com is "http://live.com/ppsecure/post.srf".
  2. Create a string containing the required form values and write it to the request stream:
    Code:
    Dim formValues As String = "login=your username&passwd=your password"
    You can obtain a reference to the request stream via the HttpWebRequest.GetRequestStream method.
  3. Send the request by calling the HttpWebRequest.GetResponse() method. Before sending the request, you'll need to set the Method, CookieContainer, ContentType, and ContentLength properties to appropriate values.
  4. Save the cookies contained in the HttpWebResponse.Cookies property. These cookies will need to be sent with next request.

I would recommend getting an application that sniffs HTTP headers for you (such as ieHTTPheaders) to see what the browser is sending and receiving - this will help you figure out what to do in your application.

All of that being said, it would probably be much easier to use the WebBrowser control to navigate a site since there's a whole host of issues you'll need to address if you continue on this path - active scripting being the largest and most difficult of them. Is there a specific reason you don't want to use the WebBrowser control?

Finally, live.com is a bit different from the "normal" site as they use Passport for authentication. Since the basic process above doesn't work with live.com but does work with XVBT, I think there's other things that need to be sent along with the user's credentials.

Additionally,
Browsers are too slow, IMO. When I compare loading a page in IE and loading it using webrequest, it is perhaps 5 times faster. Plus, navigating is never really safe defending on what the designers of the site will do to change something. Webrequest is more reliable and faster.
Reply With Quote
  #8  
Old 09-08-2007, 04:49 AM
shaul_ahuva"loggin in" to a site? shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Quote:
Originally Posted by py343 View Post
Webrequest is more reliable and faster.
Use the HttpWebRequest class doesn't magically handle changes to a site for you - the reliability would be about the same as a web browser. Also, using the HttpWebRequest raises three big issues right away:

- Parsing the HTML
- Providing a hosting environment for scripts
- Learning HTTP so you can create requests and respond to the various status codes correctly

In other words, if a site makes heavy use of DHTML and AJAX it's going to be a major headache for you,

When determining what technology to use, performance isn't the only factor. There's something to be said for not reinventing the wheel - if the development time will take many months or years then you need to determine if the performance gains outweigh the time investment.
Reply With Quote
  #9  
Old 09-08-2007, 11:52 AM
py343 py343 is offline
Centurion
 
Join Date: Aug 2007
Posts: 120
Default

Quote:
Originally Posted by shaul_ahuva View Post
Use the HttpWebRequest class doesn't magically handle changes to a site for you - the reliability would be about the same as a web browser. Also, using the HttpWebRequest raises three big issues right away:

- Parsing the HTML
- Providing a hosting environment for scripts
- Learning HTTP so you can create requests and respond to the various status codes correctly

In other words, if a site makes heavy use of DHTML and AJAX it's going to be a major headache for you,

When determining what technology to use, performance isn't the only factor. There's something to be said for not reinventing the wheel - if the development time will take many months or years then you need to determine if the performance gains outweigh the time investment.
So far, it works well enough to download the titles of the subjects of the first page, so logging in works. Now, I have to download all of the titles, and that requires the use of cookies.

During which get/post to I get the cookie, how do I do it? And during the GET that I need to use to use to get more info, how do I introduce the cookie there?

Okay, I solved it. The problem was not with the cookies, but with the session id. However, cookies were also important.

Last edited by py343; 09-08-2007 at 05:31 PM.
Reply With Quote
  #10  
Old 09-09-2007, 03:39 PM
gazmac's Avatar
gazmac gazmac is offline
Junior Contributor
 
Join Date: Apr 2003
Posts: 200
Default

I've been trying to achieve this for a while.

Here is what I have so far:

Code:
    Function Send_HTTP_Post(ByVal RequestURL As String, ByVal SendData As String) As String

        Dim DataByte() As Byte = Encoding.ASCII.GetBytes(SendData)
        Dim Req As WebRequest = HttpWebRequest.Create(RequestURL)
        Dim Cookies As CookieContainer = Nothing

        With Req
            .ContentType = "multi-part/form-data"
            .ContentLength = DataByte.Length
            .Method = "POST"
        End With

        Dim Response As HttpWebResponse = Req.GetResponse

        For Each _Cookie As Cookie In Response.Cookies
            Cookies.Add(_Cookie)
        Next

        Return Response.ToString

    End Function
This just hang's at ...Req.GetResponse. Is this a common problem I can overcome?

Thanks.
Reply With Quote
  #11  
Old 09-09-2007, 06:13 PM
py343 py343 is offline
Centurion
 
Join Date: Aug 2007
Posts: 120
Default

Quote:
Originally Posted by gazmac View Post
I've been trying to achieve this for a while.

Here is what I have so far:

Code:
    Function Send_HTTP_Post(ByVal RequestURL As String, ByVal SendData As String) As String

        Dim DataByte() As Byte = Encoding.ASCII.GetBytes(SendData)
        Dim Req As WebRequest = HttpWebRequest.Create(RequestURL)
        Dim Cookies As CookieContainer = Nothing

        With Req
            .ContentType = "multi-part/form-data"
            .ContentLength = DataByte.Length
            .Method = "POST"
        End With

        Dim Response As HttpWebResponse = Req.GetResponse

        For Each _Cookie As Cookie In Response.Cookies
            Cookies.Add(_Cookie)
        Next

        Return Response.ToString

    End Function
This just hang's at ...Req.GetResponse. Is this a common problem I can overcome?

Thanks.
It hangs? Did you close the request once you were finished? Also, I found that it hangs with hotmail, although I got it to work with another email service.
Reply With Quote
  #12  
Old 09-09-2007, 07:44 PM
AtmaWeapon's Avatar
AtmaWeapon"loggin in" to a site? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

Quote:
Originally Posted by gazmac View Post
I've been trying to achieve this for a while.

Here is what I have so far:

Code:
    Function Send_HTTP_Post(ByVal RequestURL As String, ByVal SendData As String) As String

        Dim DataByte() As Byte = Encoding.ASCII.GetBytes(SendData)
        Dim Req As WebRequest = HttpWebRequest.Create(RequestURL)
        Dim Cookies As CookieContainer = Nothing

        With Req
            .ContentType = "multi-part/form-data"
            .ContentLength = DataByte.Length
            .Method = "POST"
        End With

        Dim Response As HttpWebResponse = Req.GetResponse

        For Each _Cookie As Cookie In Response.Cookies
            Cookies.Add(_Cookie)
        Next

        Return Response.ToString

    End Function
This just hang's at ...Req.GetResponse. Is this a common problem I can overcome?

Thanks.
Why are you not writing any data to the request stream? You told the remote host to expect data of a certain length, but then you never send that data.

Additionally, you're going to get a NullReferenceException when you try to add cookies. The chain of use for Cookies is:
Dim Cookies As CookieContainer = Nothing
...
Cookies.Add(_Cookie)


What you probably want instead is to do something like:
Cookies = Response.Cookies
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #13  
Old 09-09-2007, 08:21 PM
gazmac's Avatar
gazmac gazmac is offline
Junior Contributor
 
Join Date: Apr 2003
Posts: 200
Default

Quote:
Originally Posted by AtmaWeapon View Post
Why are you not writing any data to the request stream? You told the remote host to expect data of a certain length, but then you never send that data.
Ah, of course. How silly of me.

I ran the function without a ContentLength to see where I got and I loose the hang, however, I'm not familiar with WebRequests; am I to add the relevant data to the .Headers property here? If I do so then (I believe) the data doesn't meet up to the expected ContentLength.

Also, a side note for people who may have used any of the code listed, the Response.Cookies returns a CookieCollection, not a CookieContainer.
Reply With Quote
  #14  
Old 09-09-2007, 11:34 PM
AtmaWeapon's Avatar
AtmaWeapon"loggin in" to a site? AtmaWeapon is offline
Fabulous Florist

Forum Leader
* Guru *
 
Join Date: Feb 2004
Location: Austin, TX
Posts: 9,500
Default

No idea. RFC 2616 section 9.5 describes POST methods, but points out that the implementation is server-specific. I'm sure you add the data to the header, but what the server expects will vary.
__________________
.NET Resources
My FAQ threads | Tutor's Corner | Code Library
I would bet money 2/3 of .NET questions are already answered in one of these three places.
Reply With Quote
  #15  
Old 09-10-2007, 06:58 AM
shaul_ahuva"loggin in" to a site? shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

GET requests should include the data in the request url (specified during the call to HttpWebRequest.Create). POST requests should include the data in the message body (available via WebRequest.GetRequestStream), but it seems that IIS allows you to specify data in the url as well. I'm not sure about other web servers.

The headers of HTTP messages indicate the type of data, what to do with data/message, status, cookies, cache settings, etc. The Content-Length header is supposed to identify how long the message body is. Therefore, content-related headers such as Content-Length and Content-Type only apply to POST requests.
Reply With Quote
  #16  
Old 09-10-2007, 12:32 PM
py343 py343 is offline
Centurion
 
Join Date: Aug 2007
Posts: 120
Default

I have another question, this worked with my email account on one server, but I am having trouble implementing it for Hotmail HTTP mail. Does anyone know how Hotmail HTTP mail works? What does it expect?
Reply With Quote
  #17  
Old 09-10-2007, 01:27 PM
shaul_ahuva"loggin in" to a site? shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

Have you tried downloading a HTTP header sniffing program as I suggested and seeing for yourself what Hotmail is expecting?
Reply With Quote
  #18  
Old 09-10-2007, 01:35 PM
py343 py343 is offline
Centurion
 
Join Date: Aug 2007
Posts: 120
Default

Quote:
Originally Posted by shaul_ahuva View Post
Have you tried downloading a HTTP header sniffing program as I suggested and seeing for yourself what Hotmail is expecting?
Yeah, I have. It expects a ton of cookies. I copied the POST URL completely, with pass and username, but it says it is invalid if I paste it. I think it uses some kind of a complex request cookie/sessionid system.
Reply With Quote
  #19  
Old 09-10-2007, 07:32 PM
shaul_ahuva"loggin in" to a site? shaul_ahuva is offline
Ultimate Contributor

Retired Leader
* Expert *
 
Join Date: Jul 2003
Location: Camp Hill, PA
Posts: 1,992
Default

When you say POST url, did you include the credentials in the url or the form? If in the url, the web app might only be looking at the form (WebRequest.GetRequestStream).
Reply With Quote
  #20  
Old 10-08-2007, 03:42 AM
aum4us aum4us is offline
Newcomer
 
Join Date: Oct 2007
Posts: 6
Default

Hi am new to this Site.
Anyone help me how we can design a WebPage to lonin to another site (by giving UserID and Passoword) and create object and to save as html file.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
"loggin in" to a site?
"loggin in" to a site?
"loggin in" to a site? "loggin in" to a site?
"loggin in" to a site?
"loggin in" to a site?
"loggin in" to a site? "loggin in" to a site? "loggin in" to a site? "loggin in" to a site? "loggin in" to a site? "loggin in" to a site? "loggin in" to a site?
"loggin in" to a site?
"loggin in" to a site?
 
"loggin in" to a site?
"loggin in" to a site?
 
-->