首页 > 代码库 > Php 通过curl提交post内容为 Json的请求

Php 通过curl提交post内容为 Json的请求

<?php
$data = http://www.mamicode.com/array("cNos" => "123456", "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)
?>

Php 通过curl提交post内容为 Json的请求