您当前的位置: 首页 > 学无止境 > 心得笔记 网站首页心得笔记
curl下post方式传递json数据
发布时间:2017-05-23 09:02:04编辑:雪饮阅读()
//curl的post传递json
function http_post_json($url, $jsonStr) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json; charset=utf-8', 'Content-Length: ' . strlen($jsonStr)));
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
return array($httpCode, $response);
}
关键字词:curl,json,post
上一篇:wdcp下升级mysql5.2.17至mysql5.5
下一篇:linux更新时间