Filling Form with WinINet

Started by
7 comments, last by Prozak 20 years, 5 months ago
Im starting to mess with WinINet. I''ve been able to download the html code for my webpage, using an online tutorial. But now I want to navigate to a page with a simple form and fill it out (not visually, this all happens in the background, like when you use some sort of Instant Messenger, and you fill in the email and password bits, and it sends that back to a server). Well, I want to create some sort of website sidekick, a simple program that sits in my systray and checks my website every 60 seconds for updates and stuff... google returns a lot of junk... Thanx for any tips!

[Hugo Ferreira][Positronic Dreams]
All your code are belong to us!

Advertisement
someone?
*bump*
HTML is just a language to display fancy text - you need to use HTTP to send data back and forth. To ''fill in the form'', what you''d really be doing is finding what fields a script needs and requesting that script via http with the proper variables filled in.
Google gives some seemingly related pages(didn''t read them) for:http form request header wininet
"Walk not the trodden path, for it has borne it's burden." -John, Flying Monk
Like I told you before, this is a job MUCH easier done with the right tool (maybe perl, python, or a shell script). I''d be suprised if this took longer than 20 minutes if you used the right tool. This would be a snap for a handful of unix tools used together (which are all available for Windows as well).
You wanna make a program do a HTTP POST call on your website throwing some data in along the way - correct?

-------------
E-)mil
"I feel like... I feel like...
Like taking over the world!"
- Day of the Tentacle
Emil Johansen- SMMOG AI designerhttp://smmog.com
Ya.
This is useful for me in many fronts. With this i can create a website sidekick, that checks the website every 90 secs and warns me of new news or posts in the forums.

I can also add it to my engine so that in the debug phase ppl can upload their stats with the press of a button, instead of going through all the steps in between...

Its very useful stuff...

[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine]
All your code are belong to us!

I know what you mean - I myself created a similar administration system for a website. To spare you from doing double work I have posted a function that takes care of it all, but I reccomend that you read up on the functions on this url:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wininet/wininet/wininet_functions.asp

Well - here goes the function:
#include <windows.h> //for the MessageBox function - I believe it is required in order to user wininet as well#include <wininet.h> //for all the wininet functions/*Also - you need to use wininet.lib to run wininet. In VC++ you can add this to the project by selecting settingsin the project menu and then on the link pane in the category "general" add "wininet.lib" to the end of the string inthe "object/library modules" text box*///Just a simple function to handle errors - put anything you want in herevoid error(const char *message){	MessageBox(0,string(message).c_str(),"Error",0);}//---------------------------------------------------------------------------LPTSTR post(LPSTR serverName, LPSTR scriptName, LPSTR data){	LPTSTR lpszData="";	HINTERNET hInternet=InternetOpen("bot",INTERNET_OPEN_TYPE_PRECONFIG,NULL,NULL,NULL);	if(hInternet){		HINTERNET hConnection=InternetConnect(hInternet,serverName,INTERNET_DEFAULT_HTTP_PORT,"anonymous","anonymous",INTERNET_SERVICE_HTTP,NULL,NULL);		if(hConnection){			HINTERNET hRequest=HttpOpenRequest(hConnection,"POST",scriptName,NULL,NULL,NULL,NULL,NULL);			if(hRequest){				LPSTR header="Content-Type: application/x-www-form-urlencoded";				if(HttpSendRequest(hRequest,header,strlen(header),data,strlen(data))){					DWORD dwSize;					if(InternetQueryDataAvailable(hRequest,&dwSize,0,0)){						lpszData=new TCHAR[dwSize+1];						DWORD dwDownloaded;						if(InternetReadFile(hRequest,(LPVOID)lpszData,dwSize,&dwDownloaded))							lpszData[dwDownloaded]='\0';						else							error("Unable to read response data: ");					}else						error("Unable to read response size: ");				}else					error("Unable to send request: ");				InternetCloseHandle(hRequest);			}else				error("Unable to open request: ");			InternetCloseHandle(hConnection);		}else			error("Unable to open connection: ");		InternetCloseHandle(hInternet);	}else		error("Unable to initialize internet: ");	return lpszData;}


-------------
E-)mil
"I feel like... I feel like...
Like taking over the world!"
- Day of the Tentacle

[edited by - emileej on October 26, 2003 4:06:18 AM]
Emil Johansen- SMMOG AI designerhttp://smmog.com
Thanx for the tip emileej

[Hugo Ferreira][Positronic Dreams][Colibri 3D Engine]
All your code are belong to us!

This topic is closed to new replies.

Advertisement