php发送post请求json数据
2025-04-14 Umming PHP学习 评论(0) 浏览(256)
function list(){ $url = '接口地址'; $sign = strtoupper(md5('0001加密字符')); $postData = [ 'deptId' => '0001', 'sign' => $sign ]; $options = [ 'http' => [ 'header' => "Content-type: application/x-www-form-urlencoded\r\n", 'method' => 'POST', 'content' => http_build_query($postData) ] ]; $context = stream_context_create($options); // 发送请求并获取响应 $response = file_get_contents($url, false, $context); if ($response === false) { // 处理错误 JsonReturn(['code'=>1,'msg'=>'接口服务网络出错!']); } else { //$json = json_encode($response); //JsonReturn(['code'=>0,'data'=>$json]); echo $response; } }
下一篇: nginx跨域代理解决第三方接口跨域
本文链接:https://www.umming.com/php/381.html
声明:本站信息由网友自行发布或来源于网络,真实性、合法性由发布人负责,请仔细甄别!本站只为传递信息,我们不做任何双方证明,也不承担任何法律责任。文章内容若侵犯你的权益,请联系本站删除!
也许你还会对下面的内容感兴趣:
发表评论: