Click to See Complete Forum and Search --> : I need help with doing automated login...


Ben_Phillips
December 13th, 2004, 05:50 PM
I am trying to figure out how to do automated logins on webpages, but I have no idea of how to format a POST request to a server. Specifically I am trying to log in to a simple php webpage with only two form fields titled "username" and "password". Its php page for handling the login is '/login.php'. I need to login to this webpage and retrieve the html for some pages. I know how to get the html for pages using a GET request, but I need to know how to format a POST request. Any help here would be greatly appreciated!

I am using the CInternetSession, CHttpConnection, and CHttpFile to do the server communications. I open up a connection to the server with the GetHttpConnection method of the CInternetSession class and then with my CHttpConnection class I use OpenRequest with the first argument as CHttpConnection::HTTP_VERB_POST, the second as "/login.php", and the rest are insignificant (I hope, *EDIT* for the request flags I use INTERNET_FLAG_EXISTING_CONNECT and INTERNET_FLAG_NO_AUTO_REDIRECT ). I am stuck as to what to do with the headers to format the POST.

Thank you in advance.

- Ben Phillips

drewdaman
December 14th, 2004, 11:13 AM
hey ben,

i have only used php for a small project once and i don't remember much. so i can't really help you with your question. i don't know how familiar people on this forum might be with it either... what i can do is point you to another forum where you might get more responses: http://www.phpfreaks.com/. you usually get quick responses there.

j0nas
December 14th, 2004, 04:44 PM
I haven't tested this myself, but there is a MSDN article that describes how to post a form using WinInet: http://support.microsoft.com/kb/165298/EN-US/

I think a good complement to this is to also listening in on the communication between the browser and the web-site. You can then compare the results between your app's posts and the "real" post from the browser. A nice software for capturing the communication is Ethereal (http://www.ethereal.com/download.html).

Good luck.

Ben_Phillips
December 14th, 2004, 05:10 PM
Thank you j0nas that happens to be exactly what I am looking for!

Amorphis
February 7th, 2005, 11:44 AM
As far as I see in example offered by jOnas I can use only IE for send request for any site with posted data.

But can I use for this purpose default browser?

It is really simple with GET method: I have to make an URL-string and just call ShellExecute with command "open" and this URL as parameter. Default browser will be called.

Can I use POST method to translate data with http request using default browser, not only IE?

Thank you.