Page 1 of 1

Capturing POST Header Responses

Posted: Mon Nov 20, 2006 10:05 am
by kendall
Hello,

This is a theory question in which i seek insight on its workings...

I am trying to code for a ecommerce driven process in which i use a form to post information through https protocol and a response is "posted" back in the form of a header xml data...I am trying to understand the concept of this as i am unsure of this process.

what has been documented by my ecommerce provider is that the variables posted from my form to a thier url is processed and a response in the form of

Code: Select all

Header
HTTP/1.1 200 OK
Content-Type: text/xml; charset=utf-8
Content-Length: length
Body
<?xml version="1.0" encoding="utf-8"?>
<string xmlns="http://someurl.com/">RESPONSEDATA</string>
is posted back to the calling url...(i'm assuming its the form page that i posted from?...would it be?)

them im to do what is necessary with the results. Now on running atest on this the xml above is outputted directly to the screen...but i am supposed to parse this xml content and do what i need to do accordingly...

do you understand this concept?
what i am confused with is if they "posted" back as h eader information how do i capture this in PHP ?

if you guys dont understand the question then let me know so that i can maybe explain in more details

Kendall[/syntax]

Posted: Mon Nov 20, 2006 11:26 am
by volka
POST data is not within the http headers. And it's also not a term used for a http repsonse. A http request may use the POST method and therefore have POST data appended. The other way round it's almost the same but it's not called POST anyway ;)
Let's what request my browser sends to devnetwork.net when I hit the preview button right now.
POST /posting.php HTTP/1.1
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; de; rv:1.8.1) Gecko/20061010 Firefox/2.0
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-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Content-Type: application/x-www-form-urlencoded
Content-Length: 592

subject=a&addbbcode100=-1&addbbcodefontcolor=%23444444&addbbcodefontsize=12&helpbox=Font+color%3A
+%5Bcolor%3Dred%5Dtext%5B%2Fcolor%5D++Tip%3A+you+can+also+use+color%3D%23FF0000&message=POST+data+
is+not+within+the+http+headers.+And+it%27s+also+not+a+term+used+for+a+http+repsonse.+A+http+request
+may+use+the+POST+method+and+therefore+have+POST+data+appended.+The+other+way+round+it%27s+almost
+the+same+but+it%27s+not+called+POST+anyway+%3B%29%0D%0ALet%27s+what+request+my+browser+sends+to+devnetwork.net
+when+I+hit+the+preview+button+right+now.&attach_sig=on&mode=reply&t=59272&preview=Preview
(removed some headers, added some line breaks)
You see it sends the headers then a blank line. Everything after that first blank line is the request body (not the request header anymore). According to the request method (POST /posting.php HTTP/1.1) it's POST data and according to application/x-www-form-urlencoded it's urlencoded (e.g. space->+).
And the server send a http response:
Code: 200 - OK
Set-Cookie: phpbb2mysql_data=[...]; expires=Tuesday, 20-Nov-07 17:21:45 GMT; path=/; domain=.devnetwork.net
phpbb2mysql_sid=[...]; path=/; domain=.devnetwork.net
Cache-Control: private, pre-check=0, post-check=0, max-age=0
Content-Type: text/html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
again there are the headers, a blank line and the payload data.

Your "ecommerce driven process" seems to want a POST request with the xml data as request body and also sends back a xml document.

Posted: Mon Nov 20, 2006 1:16 pm
by Mordred
It seems to me that you access the ecomerce backend from your browser, and not from your app, that's why the xml is output (I'm sure there's no word "outputted", but "output" does look strange here ;) ) directly to the screen.

What you probably need to do is request the xml and handle the response from your PHP application. This means either using curl, snoopy, etc., or doing it "manually" with sockets. The method of retrieving the xml is then subject to the library you chose to use.

Posted: Mon Nov 20, 2006 1:51 pm
by kendall
Modered

Aahh yeess....after fiddling
and fiddling it has been realised...sigh*...ours of time wasted...im spassed out :lol: