Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't figure out how to send a POST request.

Status
Not open for further replies.

PremiumL

MIS
Nov 3, 2004
10
US
I need to write a program that sends HTTP POST requests to navigate a website and retrieve data from it. I'm currently testing using the following website:

The site sends me a 400 error when sending the following request:

POST /cgi-bin/mycgi.pl HTTP/1.0
Content-type: text/html
Content-Length: 209

&realname=nospaces&email=blah&nosmoke=CHECKED&hatesanchovies=UNCHECKED&shakespea
re=UNCHECKED&washesdaily=UNCHECKED&beach=UNCHECKED&brooklyn=UNCHECKED&dogs=UNCHE
CKED&cats=UNCHECKED&iguanas=UNCHECKED&myself=blah


HTTP/1.1 404 Not Found
Date: Thu, 13 Jan 2005 17:16:40 GMT
Server: Apache
Content-Length: 290
Connection: close
Content-Type: text/html; charset=iso-8859-1

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /cgi-bin/mycgi.pl was not found on this server.</p>
<hr />
<address>Apache Server at prancer.anywherehost.net Port 80</address>
</body></html>


Is my request contstructed correctly?
 
Don't waste your time trying to construct HTTP headers yourself. LWP::UserAgent (look for it on can make POST requests. Google for "lwpcook" for a tutorial on using the LWP modules for doing web-based stuff.
 
Check the webserver logs to see if more info is available

Seems that the file isn't available at the specified address, is the webserver configured with a ScriptAlias for cgi-bin, is the cgi-bin you're referring to the same as the one where the file actually resides. Try putting the absolute webaddress
HTH
--Paul

cigless ...
 
>> Unfortunately, I don't know PERL. I'm using C/C++.
Sorry 'bout that. Because it's most common, I tend to assume Perl for CGI unless I'm told otherwise.

From what you've posted, it looks like you're trying to retrieve " which, when I type it into my browser, gives me a 404 too. That would suggest that your HTTP header is correct but that you're requesting the wrong page.
 
I have a similar issue to figure out. Now i know this CAN be done I just don't have a clue how. Now this URL will return an error 404 regardless of what you do, the script is there I can use it but the problem is that unless the results below are returned from the server the script will not properly execute.

I require the result of this URL to be returned.

A correctly returned page will consist of:

<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="TEXT/HTML">
<META HTTP-EQUIV="REFRESH" CONTENT="1;URL=
NULL">
</HEAD>
</HTML>

Now if the HTML above is returned and the appropriate query string is applied this script will send and SMS text message.

I have tested it and IE6 will execute the script and return 404 error. programatic loading of the URL returns error 500 or 404 with now script execution.

I am stumped on this one. Any ideas?
 
Well after plenty of hard work i have solved this problem. LOL After passing all of the Headers I could think of with the POST I got it to work.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top