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

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.

Who is Participating?

Improve company productivity with a Business Account.Sign Up

v2MediaConnect With a Mentor Commented:
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:
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?
jallenmorrisAuthor Commented:
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

jallenmorrisAuthor Commented:

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.
jallenmorrisAuthor Commented:
Thanks for your help.
jallenmorrisAuthor Commented:
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.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.