Page 1 of 1

sending a http request with post

Posted: Wed May 15, 2002 11:39 am
by jaybee
I need to send a post request to a remote server and receive an xml doc in response. Iunderstand that I need to use header() but keep getting a 500 (Internal Server) error - in the server log it says "bad header". This is the header I want to send:

Code: Select all

POST /xmlapi HTTP/1.0
Cookie: pgfh354=encrypted_password
Content-type: application/x-www-form-urlencoded
Content-Length: 654654

XMLREQUEST=URL_encoded_XML_doc
and I tried to send to the remote server with this code:

Code: Select all

<?php
	header("Location: http://remotehost");
	header("PORT: 80");
	header("POST /xmlapi HTTP/1.0");
	header("Cookie: PSpcV310=encrypted_password");
	header("Content-type: application/x-www-form-urlencoded");
	header("Content-length: content_length");
	header("XMLREQUEST=encoded_XML_document\n");
?>
Any help much appreciated!

Re: sending a http request with post

Posted: Wed May 15, 2002 12:44 pm
by jason
You want to send this:

Code: Select all

POST /xmlapi HTTP/1.0
Cookie: pgfh354=encrypted_password
Content-type: application/x-www-form-urlencoded
Content-Length: 654654

XMLREQUEST=URL_encoded_XML_doc
But in fact, you are sending this:

Code: Select all

POST /xmlapi HTTP/1.0
Cookie: pgfh354=encrypted_password
Content-type: application/x-www-form-urlencoded
Content-Length: 654654
XMLREQUEST=URL_encoded_XML_doc
Change this:

Code: Select all

...snip...
header("Content-length: content_length");
header("XMLREQUEST=encoded_XML_document\n");
To this:

Code: Select all

...snip...
header("Content-length: content_length\n\n");
header("XMLREQUEST=encoded_XML_document");

Posted: Thu May 16, 2002 3:22 am
by jaybee
Thanks Jason, and may I say you're looking particularly lovely today. This fixes my first prob, in that the header is now sent. It's not doing what I want at the other end but that's another story......!

Posted: Thu May 16, 2002 7:57 am
by EvilWalrus
Header() won't work for what you show you need... look into using sockets to post data dynamicaly across files and forms..