[Solved]POST REQUEST using php headers

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
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

[Solved]POST REQUEST using php headers

Post 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
Last edited by dude81 on Mon Feb 26, 2007 10:08 pm, edited 1 time in total.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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?
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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/
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

also, maybe CURL handles POST as well, but I would use volka's suggestion first
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post 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.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post 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.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
dude81
Forum Regular
Posts: 509
Joined: Mon Aug 29, 2005 6:26 am
Location: Pearls City

Post 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.
Post Reply