Solved

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

Posted on 2007-12-05
6
1,489 Views
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:  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
0
Comment
Question by:jallenmorris
  • 4
  • 2
6 Comments
 
LVL 19

Expert Comment

by:v2Media
Comment Utility
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?
0
 

Author Comment

by:jallenmorris
Comment Utility
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

0
 
LVL 19

Accepted Solution

by:
v2Media earned 500 total points
Comment Utility
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:

http://php.assistprogramming.com/php-logindownload-file-curl-libraries.html
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:jallenmorris
Comment Utility
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.
0
 

Author Closing Comment

by:jallenmorris
Comment Utility
Thanks for your help.
0
 

Author Comment

by:jallenmorris
Comment Utility
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.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that undeā€¦
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now