Login   Register  
PHP Classes
elePHPant
Icontem

nubile question

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      PHP HTTP protocol client  >  All threads  >  nubile question  >  (Un) Subscribe thread alerts  
Subject:nubile question
Summary:how to? Reading response same as “URL-encoded” using this class
Messages:7
Author:asksam2002
Date:2005-06-17 23:18:18
Update:2005-06-23 15:15:00
 

  1. nubile question   Reply  
Picture of asksam2002
asksam2002
2005-06-17 23:18:18
Hi,
I'm nubile in PHP and using this class to access to Web API,
However the Web API return data as follow:

The MIME type will be application/x-www-form-urlencoded, because the format of the response will be the same “URL-encoded” format as the request (e.g. name1=value1&name2=value2).

Demo data it cut:
===============================
errorCode=0&noOfResults=115&1_orderNumber=357853&1_orderStatus=
Processed&1_dateTime=1118563815&1_organizationName=.....

&2_orderNumber=357853&2_orderStatus...........

&115_orderNumber=357853&115_orderStatus
===============================

My Question what is the best way to handle it.
I need to import it to db or send email base on this data.

Any Advise will be helpful thank you

Kindly Regards
Sam


  2. Re: nubile question   Reply  
Picture of Manuel Lemos
Manuel Lemos
2005-06-18 02:12:30 - In reply to message 1 from asksam2002
Use the argument PostValues to specify an associative array with names and values for the form submission you are trying to emulate.

The test_form_post.php example demonstrates how to do that.

  3. Re: nubile question   Reply  
Picture of asksam2002
asksam2002
2005-06-18 18:56:35 - In reply to message 2 from Manuel Lemos
Hi,
First of all thank you for your quick replay but,
If you mean to test_http.php or test_http_post.php

both of them get somthing like this


$error=$http->ReadReplyBody($body,1000);
if($error!=""
|| strlen($body)==0)
break;
echo HtmlSpecialChars($body);

this mean $body contain stram of text
now to be clear with my question how I take this stream that look like:
errorCode=0&noOfResults=115&1_orderNumber=357853&1_orderStatus=
Processed&....

in “URL-encoded” format and used somthign like
$res = $_POST['errorCode'] or any other form with out using split/explode

$rows = explode("&", $body);
$col = explode("=", $rows[0]);
//$col[0] = 'errorCode';
//$col[1] = '0';

Kindly Regards
Sam

  4. Re: nubile question   Reply  
Picture of Manuel Lemos
Manuel Lemos
2005-06-18 19:46:24 - In reply to message 3 from asksam2002
No, that part is to read the response, not to submit the request.

You do not need to compose the request body manually. Just use the PostValues request argument and the class does all you need.

When you use the PostValues request parameter, it submits a POST request with a request body like you want because that is how forms are submitted with the POST method.


  5. Re: nubile question   Reply  
Picture of asksam2002
asksam2002
2005-06-20 20:25:58 - In reply to message 4 from Manuel Lemos
:)
I know, the problem with this API that this is the return
and not the $arguments["PostValues"]


So, I end up that $body is look like $arguments["PostValues"]

That's mean the $body contain stream that look similar
to: $arguments["PostValues"]

again what will be the best way to convert it to real array?
Kindly Regards
Sam

  6. Re: nubile question   Reply  
Picture of Manuel Lemos
Manuel Lemos
2005-06-20 20:39:44 - In reply to message 5 from asksam2002
That is odd. I don't know what kind of service returns content of MIME type application/x-www-form-urlencoded .

Anyway, you can rebuild an array of values from that kind of data using the PHP function parse_str().

  7. Re: nubile question   Reply  
Picture of asksam2002
asksam2002
2005-06-23 15:15:00 - In reply to message 6 from Manuel Lemos
Thanks it's solved the issue
I used somthing like this and it's works

parse_str($str, $output);
echo $output['first']; // value
echo $output['arr'][0]; // foo bar
echo $output['arr'][1]; // baz

again and again thanks :)
Sam