sending a http request with post

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
jaybee
Forum Newbie
Posts: 12
Joined: Tue May 14, 2002 3:58 pm
Location: brighton, uk

sending a http request with post

Post 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!
jason
Site Admin
Posts: 1767
Joined: Thu Apr 18, 2002 3:14 pm
Location: Montreal, CA
Contact:

Re: sending a http request with post

Post 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");
User avatar
jaybee
Forum Newbie
Posts: 12
Joined: Tue May 14, 2002 3:58 pm
Location: brighton, uk

Post 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......!
User avatar
EvilWalrus
Site Admin
Posts: 209
Joined: Thu Apr 18, 2002 3:21 pm
Location: Springmont, PA USA

Post by EvilWalrus »

Header() won't work for what you show you need... look into using sockets to post data dynamicaly across files and forms..
Post Reply