Link to home
Start Free TrialLog in
Avatar of jallenmorris
jallenmorris

asked on

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:  http://www.netomatix.com/development/httpwebrequestredirect.aspx  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.

Jarod
Avatar of v2Media
v2Media
Flag of Australia image

It's not done with asp.net, 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 asp.net, do you know php and mysql databases?
Avatar of jallenmorris
jallenmorris

ASKER

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.

v2Media,

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("https://www.claimintelligence.com/CIApp/UserLoginUI.aspx")
second = get_it("https://www.claimintelligence.com/CIApp/ModuleMainMenu.aspx")
 
dim find
'ThisTitleStart = InStr(Items(a),"<title>")+16
 
response.write second

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of v2Media
v2Media
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
v2Media,

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.
Thanks for your help.
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.