Retrieve XML from HTTP POST request using php -


I have examined similar questions but no one is experiencing any problem.

I am creating a web service and I want to recover XML data from an HTTP POST request, manipulate data and return a response. The following information should be considered when writing a script:

  Communication mode is not HTTP POST (SOAP) content type text / xml in POST request Only XML will be included in the request directly to a Raw post A parameter will not be streamed in and.  

I tried but my script is not capturing data from the HTTP POST request.

My script:

  $ postData = file_get_contents ('php: // input'); If (empty! ($ Xml-> Merchant Reference)) {$ merchRef = (string) $ xml- & gt; Merchant Reference; $ CustRef = (int) $ xml- & gt; CustReference; $ Username = (string) $ xml- & gt; ServiceUsername; $ Password = (string) $ xml- & gt; Service passwords; $ Db- & gt; Settlement (check if the customer is present in the database); If ($ db-> countResultset () == 0) {header ("content-type: text / xml"); Echo "& lt ;? Xml version = '1.0' encoding = 'UTF-8'? & Gt;"; Echo "& lt; Customer Information Response & gt;"; Echo "merchantReference"; $ MerchRef "& Lt; / MerchantReference>"; Echo "& lt; Customer & gt;"; Echo "& lt; Customer & gt;"; Echo " 0 "; Echo "& lt; CustReference & gt;" $ CustRef "& Lt; / CustReference>"; Echo ""; Echo "& lt; LastName / & gt;"; Echo "& lt; alias / & gt;"; Echo "& lt; email / & gt;"; Echo "& lt; phone / & gt;"; Echo "& lt; ThirdPartyCode / & gt;"; Echo "status message" is valid for customer & lt; / status message & gt; "; Echo "& lt; / customer & gt;"; Echo "& lt; / customer & gt;"; Echo "& lt; / Customer Information Response & gt;"; Go out; }  

This is a HTTP postal request:

  & lt; Customer Incomplete Spacexmlls: ns2 = "http://test.url.com/" xmlns: NS3 = "http://www.w3.org/2003/05/soap-envelope" & gt; & Lt; ServiceUrl & gt; My URL & lt; / ServiceUrl & gt; & Lt; ServiceUsername & gt; 12345 & lt; / ServiceUsername & gt; & Lt; ServicePassword & gt; Abcdef & lt; / ServicePassword & gt; & Lt; RouteId & gt; HTTPGENERICv31 & lt; / RouteId & gt; & Lt; Services & gt; Bill & lt; / Services & gt; & Lt; MerchantReference & gt; 123456 & lt; / MerchantReference & gt; & Lt; CustReference & gt; Abcdef & lt; / CustReference & gt; & Lt; PaymentItemCategoryCode / & gt; & Lt; RequestReference / & gt; & Lt; TerminalId / & gt; & Lt; Amount & gt; 0 & lt; / Zodiac & gt; & Lt; FtpUsername / & gt; & Lt; FtpPassword / & gt; & Lt; / CustomerInformationRequest & gt;  

To retrieve and add data, my script should be how to respond: < / P>

  & lt; Customer Information Response & gt; & Lt; MerchantReference & gt; 3527 & lt; / MerchantReference & gt; & Lt; Customers & gt; & Lt; Customers & gt; & Lt; Status & gt; 0 & lt; / Status & gt; & Lt; CustReference & gt; 4565 & lt; / CustReference & gt; & Lt; FirstName & gt; & Lt; / First name & gt; & Lt; Last name & gt; & Lt; / Last name & gt; & Lt; OtherName & gt; & Lt; / OtherName & gt; & Lt; Email & gt; & Lt; / Email & gt; & Lt; Phone & gt; & Lt; / Phone & gt; & Lt; ThirdPartyCode / & gt; & Lt; Status message & gt; The customer is valid & lt; / Status message & gt; & Lt; / Customer & gt; & Lt; / Customers & gt; & Lt; / CustomerInformationResponse & gt; After a lot of research, I got the answer to my question  

I found out After receiving the data from the HTTP post request, I did not store it as XML data.

Therefore, add this line of code

  $ xml = simplexml_load_string ($ POSTDATA);  

After this

  $ postData = file_get_contents ('php: // input'); I resolved that I should share it because it could be useful for anyone. 


Comments

Popular posts from this blog

apache - 504 Gateway Time-out The server didn't respond in time. How to fix it? -

c# - .net WebSocket: CloseOutputAsync vs CloseAsync -

c++ - How to properly scale qgroupbox title with stylesheet for high resolution display? -