请求头设置为UTF-8 然后需提交的中文内容用 urlencode() 函数处理下就行了
废话不多说直接贴代码:
以下代码:
$customerName = $param['customerName'];
$url = 'http://127.0.0.1:8000/v1/add_custom?customerName='.urlencode($customerName);
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_HTTPHEADER => array(
'content-type: application/x-www-form-urlencoded; charset=UTF-8'
),
));
$ret = curl_exec($curl);
$ret = json_decode($ret,true);
curl_close($curl);
小结 在调用第三方接口的时候一定要先阅读开发须知,真的很帮助我们的开发哦. 感谢您的阅读~~
|