脚本宝典收集整理的这篇文章主要介绍了PHP基于curl模拟post提交json数据示例,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
本文实例讲述了PHP基于curl模拟post提交json数据。分享给大家供大家参考,具体如下:
这里PHP模拟post提交json数据操作的关键是在头部设置Content-tyPE
<
PRe class="
brush:
PHp;">
"
test001","pass"=>"xxxx",);
$data = json_encode($par
am);
list($return_code,$return_content) = http_post_data($url,$data);//return_code是http状态码
print_r($return_content);ex
IT;
function http_post_data($url,$data_string) {
$ch =
curl_init();
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch,CURLOPT_HTTPHEADER,array(
"Content-Type: application/json; charset=utf-8","Content-Length: " .
strlen($data_string))
);
ob_start();
curl_exec($ch);
$return_content = ob_get_contents();
ob_end_clean();
$return_code = curl_getinfo($ch,CURLINFO_HTTP_CODE);
return array($return_code,$return_content);
}
脚本宝典总结
以上是脚本宝典为你收集整理的PHP基于curl模拟post提交json数据示例全部内容,希望文章能够帮你解决PHP基于curl模拟post提交json数据示例所遇到的问题。
如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。