Solved

How do I programmatically submit data to a web page?

Posted on 2004-03-24
13
426 Views
Last Modified: 2008-02-01
Hi,

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!

Sung-En
0
Comment
Question by:sungenwang
  • 5
  • 4
  • 3
  • +1
13 Comments
 
LVL 44

Assisted Solution

by:Karl Heinz Kremer
Karl Heinz Kremer earned 100 total points
Comment Utility
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/upload.pl HTTP/1.1\r\n
Accept: */*\r\n
Referer: http://yourhost/cgi-bin/upload.pl\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
\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:
---------0xKhTmLbOuNdArY\r\n
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...
0
 
LVL 23

Accepted Solution

by:
chensu earned 340 total points
Comment Utility
HOWTO: Automate Internet Explorer to POST Form Data
http://support.microsoft.com/default.aspx?scid=kb;en-us;167658

SAMPLE: PostMon.exe Demonstrates How to Use URL Moniker to POST Data
http://support.microsoft.com/default.aspx?scid=kb;en-us;165800

HOWTO: Use the PostData Parameter in WebBrowser Control
http://support.microsoft.com/default.aspx?scid=kb;en-us;174923
0
 
LVL 14

Author Comment

by:sungenwang
Comment Utility
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!
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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.
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
>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.
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
Makes sense. I got confused by the filename upload.cvs and assumed that the requirement was to actually upload the file.
0
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
LVL 14

Author Comment

by:sungenwang
Comment Utility
Chensu is right. Just the file name.

Any luck in finding the article on sending the id & password? I believe it was something like:
www.idname:password:domainname.com
I tried
0
 
LVL 14

Author Comment

by:sungenwang
Comment Utility
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...
0
 
LVL 14

Author Comment

by:sungenwang
Comment Utility
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...
0
 
LVL 23

Expert Comment

by:chensu
Comment Utility
You can provide a user name and password as part of the URL for FTP.

How to Enter FTP Site Password in Internet Explorer
http://support.microsoft.com/default.aspx?scid=kb;en-us;Q135975
0
 
LVL 44

Expert Comment

by:Karl Heinz Kremer
Comment Utility
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.
0
 
LVL 5

Assisted Solution

by:phyderous
phyderous earned 60 total points
Comment Utility
You can use the IXMLHTTPREQUEST

documentation can be found in

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk30/htm/xmobjxmlhttprequest.asp

this is a very simple COM object that allow you post http data to a web server
0
 
LVL 14

Author Comment

by:sungenwang
Comment Utility
Thanks to you all!
I think I'm on my way now... sungen
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.

763 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

7 Experts available now in Live!

Get 1:1 Help Now