Page 1 of 1
[Solved]POST REQUEST using php headers
Posted: Sun Feb 25, 2007 10:39 pm
by dude81
Hi
Is it possible to send a POST request by setting the POST request in page headers. If so let me know where do I put POST in the headers.
Thanks
Posted: Sun Feb 25, 2007 10:48 pm
by volka
Let's take a look at the request my browser send for retrieving this page. It opens a socket to the server and send the following "text"
GET /posting.php?mode=reply&t=64216&sid=[...] HTTP/1.1
Host: forums.devnetwork.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.8,de-de;q=0.5,de;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: [...]
A equvivalent post request is
POST /posting.php HTTP/1.1
Host: forums.devnetwork.net
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1.2) Gecko/20070219 Firefox/2.0.0.2
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.8,de-de;q=0.5,de;q=0.3
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Cookie: [...]
Content-Length: 28
mode=reply&t=64216&sid=[...]
What are you trying to achieve?
Posted: Sun Feb 25, 2007 10:55 pm
by dude81
I'm using an external webservice whose requirement is to pass an xml string using soap through a POST request. So I thought of setting php headers should work. How do I set it in php header function. My question is also about where do I put the POST in header function.
Posted: Sun Feb 25, 2007 10:58 pm
by volka
You cannot use header() for that. header() is used to set a response-header not to initiate a request.
Take a look at
http://de2.php.net/soap and/or
http://sourceforge.net/projects/nusoap/
Posted: Mon Feb 26, 2007 3:01 am
by Kieran Huggins
also, maybe CURL handles POST as well, but I would use volka's suggestion first
Posted: Mon Feb 26, 2007 4:01 am
by dude81
Yes, I'm using SOAP(volka's suggestion) anyhow, but I had two ways, do it through POST as well as SOAP. SOAP is ideal becuase it is a webservice.
Posted: Mon Feb 26, 2007 11:35 am
by volka
dude81 wrote: but I had two ways, do it through POST as well as SOAP. SOAP is ideal becuase it is a webservice.
? please explain.
Posted: Mon Feb 26, 2007 1:58 pm
by pickle
Not sure if you've got your answer, but I recently had to send POST data as well. Do a Google search for something along the lines of "PHP send POST data". There are a few examples out there that use
fsockopen() & related functions.
Posted: Mon Feb 26, 2007 9:28 pm
by dude81
pickle
Not sure if you've got your answer, but I recently had to send POST data as well
I really thank you for the solution. I'm using SOAP in full swing now and I've gone too far in it. I don't like to go back now again on fsockopen as I've crossed my deadline too.
volka
? please Explain
My Service provider initially gave me the document for POST and GET and as well as soap. That means I can use any of the method. SOAP is what is preferable by them.