Use HttpRequest to login to a website remotely, like Gmail, Hotmail, etc

Posted on 2007-12-05
Last Modified: 2010-04-21
I need to be able to login to a website remotely.  By remotely, I mean, within my code, I send a request with the login information to the url designated within my code and the remote website receives the username/password information (and any cookies if necessary, but I'm not sure how to detect the cookies if they are needed).  The remote website will receive the username/password information as if I had typed them into the input fields and hit the form submit button.  The response to sending the request remotely should be whatever page would be shown after the user logs in.  I have seen many people say that this is not even possible, or is a security risk, but that's not the case at all.  

If you look at this URL:  then you will see that it is definitely possible.  This programmer has done something like it in the past, I just can't find code.  One draw back is that I do not know ASP.NET, but am working on learning it.  I've programmed in classic ASP and PHP for 7 years.  The website, upon logging in, may send cookies that I will need to detect and send back with any future requests.

This question is worth 500 points and much admiration if you can help me out with this.  I apologize for needing very specific examples and/or working code.  I have a webserver online that I can upload files to directly and see if it works.  Thanks in advance for your help.

Question by:jallenmorris
  • 4
  • 2
LVL 19

Expert Comment

ID: 20417011
It's not done with, it's done with ajax. Regardless, you'll need to also write the server-side scripts that the ajax call connects to. So if you don't know, do you know php and mysql databases?

Author Comment

ID: 20417060
I know what AJAX is, and this is not like AJAX.  This is not using javascript.  You can use ASP.NET to do this, which is why Microsoft included HttpWebRequest with ASP.NET.  I know PHP and MySQL and Classic ASP very well.


Did you even bother going to the url that I pasted in the original post?  HttpRequest sends the request and brings back the response before anything is ever sent to the browser.  It's a very useful tool and acts in a very different way than AJAX.  I've written custom AJAX applications in for other websties, but none of them required me to login to a separate website.

If you notice in the code snippet I have provided, that function uses HttpRequest to send a request to a webpage and return the response from the server, all without AJAX and all before the page is loaded.
function get_it(theURL)
	Dim HttpRequest, myImage, Status
	Set HttpRequest = Server.CreateObject("MSXML2.XMLHTTP.3.0")
	HttpRequest.Open "POST", theURL, false
	HttpRequest.setRequestHeader "Content-type", "application/x-www-form-urlencoded"
	HttpRequest.Send "txtPassword=myPasswordHere&txtUserName=myUserNameHere"
	'use this next comment line to know how to send form data
	Status = HttpRequest.responseText
	Get_It = Status
End Function
dim first, second, third
first = get_it("")
second = get_it("")
dim find
'ThisTitleStart = InStr(Items(a),"<title>")+16
response.write second

Open in new window

LVL 19

Accepted Solution

v2Media earned 500 total points
ID: 20417227
I did read it and I did look at the webpage. However I thought I prod into why you would want to adopt a new platform just to get content from an external website... As I said, it's usually done with ajax, however I now assume you're talking about a remote site that you can't upload scripts to yes?

Why bother with a new platform just for a login script when you can already do the same job with existing skills? It can also be done with php curl...

This looks to fit the bill:
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.


Author Comment

ID: 20417330

Thanks for that url.  I think that might be what I was looking for.  One thing I love about programming is that there is almost always more than one way to solve a problem.  I don't really need to download content from a website.  The use for this is rather different than most uses.  For my work, I use a web-based ASP.NET website created specifically for my company.  The problem is that we've contracted out the development so the programmers are very, very, very unresponsive to what we would like to have the web-based application do.  Essentially, it's a series of forms, but over about 30 pages that we use.  There are about 5 separate pages we use approximately 80% of the time.  I want to be able to login, and then parse the information on the page to create my own forms and then process the information.  Basically create my own GUI for the web-based application.  My supervisor has encouraged me to look into it because of my programming background since we can't get the contractor to modify the application.  For example, we have a certain task that we do, such as select an item that we need to modify or adjust.  We check a checkbox, then have to scroll down the page to hit the submit button, which takes us to another page.  We have standard language that we post into another form according to what adjustment needs to be made to the invoice/bill we are reviewing.  We get that standard language from an XLS file that each user has.  We copy and paste that standard language into the web application, then hit submit.  That saves the information and then we have to hit another button to go back to the page where we can select another item that must be modified.  In all, it is about 6 - 8 clicks for each task that we do.  If I can login and recreate my own GUI, then I can incorporate the information from the XLS into my custom GUI and eliminate many of the clicks that we are not using.  It may sound odd, but if you eleiminate even 5 - 10 seconds per item modified or adjusted, over an entire day/week/month, etc that really improves productivity.  Thanks for your help.  You get the points.

Author Closing Comment

ID: 31413041
Thanks for your help.

Author Comment

ID: 20462490
To anyone that may check this page as an answer for a question regarding the same thing.  I have gotten my script to work using cURL.  The site I'm using this on does send cookies, it also has VIEWSTATE with ASP.NET .aspx and it's working good so far.  If you want help with what you're working on, just send me an email.  jarod dot morris at gmail dot com.

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

766 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question