PHP以xml形式获取POST数据
生活随笔
收集整理的這篇文章主要介紹了
PHP以xml形式获取POST数据
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
<?php
namespace Home\Controller;use Think\Controller;class UrlController extends Controller
{//xml形式獲取post的值curlpublic function send(){$header[] = 'Content-type: text/xml';//定義content-type為xml$xml = '<xml>';$xml .= '<name>name</name>';$xml .= '<age>14</age>';$xml .= '</xml>';$url = 'http://localhost/tp/index.php/Home/Url/get';$ch = curl_init(); //初始化curlcurl_setopt($ch, CURLOPT_URL, $url);//設置鏈接curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//設置是否返回信息curl_setopt($ch, CURLOPT_HTTPHEADER, $header);//設置HTTP頭curl_setopt($ch, CURLOPT_POST, 1);//設置為POST方式curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);//POST數(shù)據(jù)$response = curl_exec($ch);//接收返回信息if (curl_errno($ch)) {//出錯則顯示錯誤信息print curl_error($ch);}curl_close($ch); //關閉curl鏈接//$response可以顯示到echo $response;//顯示返回信息,
}public function get(){/*$xmldata = file_get_contents("php://input");echo $xmldata;*/if($GLOBALS['HTTP_RAW_POST_DATA'])echo $GLOBALS['HTTP_RAW_POST_DATA'];
}
}
}
}
?
$input = $GLOBALS['HTTP_RAW_POST_DATA'];libxml_disable_entity_loader(true);$xml = simplexml_load_string($input,'SimpleXMLElement',LIBXML_NOCDATA);var_dump($xml);?
轉(zhuǎn)載于:https://www.cnblogs.com/Duriyya/p/6022230.html
總結(jié)
以上是生活随笔為你收集整理的PHP以xml形式获取POST数据的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: apache开源项目--Apache C
- 下一篇: hdu 1806 Frequent va