php http请求xml数据,使用php从HTTP POST请求中检索XML
我檢查了類似的問題但沒有解決我面臨的問題.
我正在構(gòu)建一個Web服務,我想從HTTP POST請求中檢索XML數(shù)據(jù),操縱數(shù)據(jù)并返回響應.編寫腳本時應考慮以下信息:
The communication mode is HTTP POST (not SOAP)
The content type is text/xml.
The POST request will contain only XML
The request will be a RAW POST directly to stream and NOT in a parameter.
我試過但我的腳本沒有從HTTP POST請求中捕獲數(shù)據(jù).
我的劇本:
$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 customer exists in database);
if($db->countResultset() == 0)
{
header("Content-type: text/xml");
echo "<?xml version='1.0' encoding='UTF-8'?>";
echo "";
echo "".$merchRef."";
echo "";
echo "";
echo "0";
echo "".$custRef."";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "Customer is valid";
echo "";
echo "";
echo "";
exit;
}
這是HTTP POST請求:
MY URL
12345
abcdef
HTTPGENERICv31
bill
123456
abcdef
0
檢索并操作數(shù)據(jù)后,我的腳本將返回響應.這是響應的方式:
3527
0
4565
Customer is Valid
總結(jié)
以上是生活随笔為你收集整理的php http请求xml数据,使用php从HTTP POST请求中检索XML的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (20191123)matlab绘制指定
- 下一篇: ionic tab显示到顶部去了