Php通過curl提交post內容為Json的請求

老朱教授發表於2017-11-26

<?php
$data = array(“cNos” => array(“1064917432615″,”1064917432615”), “date” => “20170515”);

$data_string = json_encode($data);
print_r($data_string);
$ch = curl_init(`http://****/BatchQuery/Post1?eId=30005`);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, “POST”);
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
`Content-Type: application/json`,
`Content-Length: ` . strlen($data_string))
);
curl_setopt($ch, CURLOPT_ENCODING, `deflate`);

$result = curl_exec($ch);
print_r($result)
?>

本文轉自94cool部落格園部落格,原文連結:http://www.cnblogs.com/94cool/p/6880035.html,如需轉載請自行聯絡原作者


相關文章