Retrieve XML from HTTP POST request using php -



Retrieve XML from HTTP POST request using php -

i have checked similar questions none solves problem i'm facing.

i'm building web service , want retrieve xml info http post request, manipulate info , homecoming response. info below ought considered while writing script:

communication mode http post (not soap) content type text/xml. post request contain xml request raw post straight stream , not in parameter.

i've tried script isn't capturing info http post request.

my script:

$postdata = file_get_contents('php://input'); if(!empty($xml->merchantreference)){ $merchref = (string)$xml->merchantreference; $custref = (int)$xml->custreference; $username = (string)$xml->serviceusername; $password = (string)$xml->servicepassword; $db->setquery(check if client exists in database); if($db->countresultset() == 0) { header("content-type: text/xml"); echo "<?xml version='1.0' encoding='utf-8'?>"; echo "<customerinformationresponse>"; echo "<merchantreference>".$merchref."</merchantreference>"; echo "<customers>"; echo "<customer>"; echo "<status>0</status>"; echo "<custreference>".$custref."</custreference>"; echo "<firstname/>"; echo "<lastname/>"; echo "<othername/>"; echo "<email/>"; echo "<phone/>"; echo "<thirdpartycode/>"; echo "<statusmessage>customer valid</statusmessage>"; echo "</customer>"; echo "</customers>"; echo "</customerinformationresponse>"; exit; }

this http post request:

<customerinformationrequest xmlns:ns2="http://test.url.com/" xmlns:ns3="http://www.w3.org/2003/05/soap-envelope"> <serviceurl>my url</serviceurl> <serviceusername>12345</serviceusername> <servicepassword>abcdef</servicepassword> <routeid>httpgenericv31</routeid> <service>bill</service> <merchantreference>123456</merchantreference> <custreference>abcdef</custreference> <paymentitemcategorycode/> <requestreference/> <terminalid/> <amount>0</amount> <ftpusername/> <ftppassword/> </customerinformationrequest>

after retrieving , manipulating data, script out homecoming response. this how response should be:

<customerinformationresponse> <merchantreference>3527</merchantreference > <customers> <customer> <status>0</status> <custreference>4565</custreference> <firstname></firstname> <lastname></lastname> <othername></othername> <email></email> <phone></phone> <thirdpartycode/> <statusmessage>customer valid</statusmessage> </customer> </customers> </customerinformationresponse>

after much research, i've found reply question. discovered after getting info http post request, didn't store xml data.

so adding line of code

$xml = simplexml_load_string($postdata);

after this

$postdata = file_get_contents('php://input');

solved it. thought should share because might useful someone.

xml http post http-post

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -