Archived

This topic is now archived and is closed to further replies.

Prozak

Filling Form with WinINet

Recommended Posts

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!

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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).

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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!

Share this post


Link to post
Share on other sites
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:

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

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 settings
in the project menu and then on the link pane in the category "general" add "wininet.lib" to the end of the string in
the "object/library modules" text box*/

//Just a simple function to handle errors - put anything you want in here

void 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]

Share this post


Link to post
Share on other sites