今天请求一个接口。postman测试可以调通,但是用curl 一直报错。最后是CURLOPT_HTTPHEADER head头没有定义编码。
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32function getZhongliangapi($url,$data){ $string=''; $signstring = json_encode($data); ksort($data, 2); foreach($data as $s){ $string.=$s.'&'; } $string.=$this->key; $signature = hash("sha256", $string); $ch = curl_init(); $headers = array( "Content-type: application/json;charset='utf-8'", // "Accept: application/json", // "Cache-Control: no-cache", // "Pragma: no-cache", ); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_TIMEOUT, 1); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_URL, $url."$signature"); curl_setopt($ch, CURLOPT_POST, TRUE); curl_setopt($ch, CURLOPT_POSTFIELDS, $signstring); ob_start(); $result = curl_exec ($ch); ob_end_clean(); curl_close ($ch); unset($ch); return $result; }
最后
以上就是多情冬天最近收集整理的关于php curl post 请求接口,要求数据json格式,带中文解决请求失败,记一下。的全部内容,更多相关php内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复