Click to See Complete Forum and Search --> : How do you format a CGI query for file download?


vlw
04-29-2003, 01:02 AM
I'm writing a winsock application that downloads data files from a website. When done manually, I go to the website and enter the name of the file I want in a box. A download dialog box then pops up, and I specify the location on my machine I want the file to go.

Two questions:

1) How can I automate this process? A CGI query should be sent from my winsock application, right?
2) How do you know what CGI query can be accepted by the target website?

Any help on this is a greatly appreciated! I am totally new to both winsock and cgi.

Thanks in advance,

Victor

BlueMonk
04-29-2003, 05:18 AM
Look at the URL when you submit the file name to the website. If the method is POST the query is coded in the URL.
Decode the query (the coding of the URL is standard) and you will get the query. If you cannot see the query in the URL that means that the method used is GET. In this case, I think that you will have to guess the query. Good luck.

AdamGundry
04-29-2003, 10:53 AM
Correct, except GET passes information on the URL and POST passes it seperately in the HTTP data (you had it the wrong way around).

You could examine the source code of the website where you enter the filename to find out the CGI being used - there should be a tag like the following:
<form method="POST" action="form.cgi">

In this case the form is using the POST method and passing data to form.cgi. You then need to send a similar CGI query from your application.

Adam

vlw
04-29-2003, 11:53 AM
Thanks for the feedback. The problem is that the URL shown on my browser doesn't change when I download the file. After pressing the download button on the webpage, a download dialog box pops up. The file is then downloaded but no query of any sort is shown on the URL.

Is there another way to find out what the query should be?

AdamGundry
04-29-2003, 03:04 PM
Right-click in the popup window and click "Properties" or "View Page Info" or whatever (depends on your browser). The dialog box shown should include the URL, with any GET information displayed.

If the form uses POST data (unlikely if it is a new window), you will need to examine the <form> HTML tag.

Adam

vlw
04-29-2003, 07:55 PM
Thanks, Adam. But the pop-up download dialog box is not a window. It's a dialog box and no "properties" tab was shown when I right-clicked on the box.

Any other way to get the URL?

vlw
04-30-2003, 01:32 AM
OK, here's what I tried. Please tell me why it doesn't work:

The URL, when I get the data (stock quote) manually, is the following:

http://quote.cboe.com/QuoteTable.asp?TICKER=dell&ALL=0

So after getting the socket to "quote.cboe.com", I sent the following CGI query:

"GET /QuoteTable.asp?TICKER=dell&ALL=0"

This didn't work and I was timed out. Can someone please tell me how to fix this? I'm totally new to CGI.

thanks in advance!

Victor

DaiWelsh
04-30-2003, 09:21 AM
Victor,

I think you may struggle getting answers here as your problem is not really CGI or ASP related (at least yet) it is to do with the HTTP protocol. Most web develoeprs take care only of the server end of the communication, you are replacing the browser on the client end (if I understand correctly).

You may want to find somewhere with details of the HTTP protocol request/response formats, but failing that from very vague memory I think the HTTP request needs to be terminated with one or two blank lines (or perhaps more correctly the headers and body need to be seperated by blank lines as with server rsponse - not sure, told you it was a vague memory). Try sending a couple of new lines characters at the end, but better still as I said find an HTTP info source ;)

HTH,

Dai