How do I programmatically submit data to a web page?


I am trying to write something in Visual C++ 6.0 that will do the following in a certain time interval (e.g. twice a day):

1. Log on to a secure website with a valid user id and password.
2. Set the value of an input text box to the full path of a file name (e.g. C:\upload.csv)
3. Submit this page.

Your help is appreciated!

LVL 14
Who is Participating?
chensuConnect With a Mentor Commented:
HOWTO: Automate Internet Explorer to POST Form Data;en-us;167658

SAMPLE: PostMon.exe Demonstrates How to Use URL Moniker to POST Data;en-us;165800

HOWTO: Use the PostData Parameter in WebBrowser Control;en-us;174923
Karl Heinz KremerConnect With a Mentor Commented:
Very likely you don't have to log into the web page and fill in the text box. This can all be done by just a post operation. It's probably best if you analyze the network traffic from a client to your server when you upload a file. You need to generate something similar like this HTTP POST request:

POST /cgi-bin/ HTTP/1.1\r\n
Accept: */*\r\n
Referer: http://yourhost/cgi-bin/\r\n
User-Agent: MyUploadProgram\r\n
Content-Type: multipart/form-data; boundary=---------0xKhTmLbOuNdArY\r\n
Authorization: Basic a2hr0m1yZ2xtcmds\r\n
Content-Length: 1454339\r\n
Connection: close\r\n
Host: myhost\r\n

Lookup what the different fields mean. The authentication is the field that contaisn your user id and the password. Make sure you understand how you create the encrypted data.

Then, you just send the file:
Content-Disposition: form -data; name="upload"; filename="myfilename.pdf"\r\n
Content-Type: application/pdf\r\n\r\n
... and here comes the actual file content...
sungenwangAuthor Commented:
Hi khkremer, thanks for the detailed input. However, it is pretty touch for me (a c programmer) to decipher this to c code.

Hi Chensu, I think the code in the first link should be very helpful! I well test it.

However, is there a way I can submit my user id and password to a webpage by putting them inside an url? I think I just read it somewhere yesterday but I can't find that "tip of the day" article! If you experts can help me locate it, that would be enough to close my questions!
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Karl Heinz KremerCommented:
You just need to send the data (after replacing certain things like the Referer, authorization information or the file size information) to port 80 on the web server.

Providing a user name and password as part of the URL only works of the script on the server does support this. THis information is usually provided as "Authorization:" information.

I looked at the three links provided by chensu, but did not see anything about file uploads.
>but did not see anything about file uploads.

I don't think sungenwang needs to upload files. What sungenwang is doing is to post the upload file name to a Web site.
Karl Heinz KremerCommented:
Makes sense. I got confused by the filename upload.cvs and assumed that the requirement was to actually upload the file.
sungenwangAuthor Commented:
Chensu is right. Just the file name.

Any luck in finding the article on sending the id & password? I believe it was something like:
I tried
sungenwangAuthor Commented:
I tried several different combinations and non of them worked... I couldn't believe I didn't print out that page when I first saw it...
sungenwangAuthor Commented:
hi khkremer, do you happen to know the syntax for:
"Providing a user name and password as part of the URL"? Even though you mentioned that it may only if the server does support this. Who knows, it may just work for me...
You can provide a user name and password as part of the URL for FTP.

How to Enter FTP Site Password in Internet Explorer;en-us;Q135975
Karl Heinz KremerCommented:
There is no standard way of passing the user id and a password as part of a URL (besides for ftp, as chensu has already explained). It depends on the server setup and is in general a bad idea, because this information will be displayed on the screen (everybody who walks by your machine can see this information), but is also stored in your browser's history.

Just ignore all the low level stuff I had in my comment. Just adding the file name is possible with the information in the articles that chensu quoted.
phyderousConnect With a Mentor Commented:

documentation can be found in

this is a very simple COM object that allow you post http data to a web server
sungenwangAuthor Commented:
Thanks to you all!
I think I'm on my way now... sungen
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.