在php中使用raw格式發送post請求,但一直無法正確取得rest api的結果,程式碼如下,請參考,謝謝
<?php
$url="rest api url";
$postData = $inputJson_encode;
$result=PostFunction($url,$postData);
echo $result."<br>";
function PostFunction($url,$postData){
$ch = curl_init();
curl_setopt( $ch, CURLOPT_URL, $url);
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt( $ch, CURLOPT_POST, 1);
curl_setopt( $ch, CURLOPT_POSTFIELDS, $postData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'X-AjaxPro-Method:ShowList',
'Content-Type: application/json; charset=utf-8',
'Content-Length: ' . strlen($postData))
);
curl_setopt($ch, CURLOPT_TIMEOUT_MS, 30000);
$result = curl_exec($ch);
$errorNo = curl_errno($ch);
return $result;
}
?>