博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
php curl发送json格式数据并获取状态码 header和body
阅读量:3555 次
发布时间:2019-05-20

本文共 1051 字,大约阅读时间需要 3 分钟。

重点在curl中指定 Content-Type: application/json; charset=utf-8

"e10adc3949ba59abbe56e057f20f883e", "username"=>"canlang" ); $data = json_encode($param); list($return_code,$headers,$return_content) = http_post_data($url, $data);print_r($return_content);exit; 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_HEADER, TRUE); //表示需要response header 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(); //获取头部 $header_size = curl_getinfo($ch, CURLINFO_HEADER_SIZE); $headers = substr($return_content, 0, $header_size); //http状态码 $return_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); return array($return_code, $headers,$return_content);}

转载地址:http://codrj.baihongyu.com/

你可能感兴趣的文章
牛客_顺时针打印矩阵
查看>>
牛客_数组中出现超过一半的数字
查看>>
图神经网络task_05
查看>>
解决spring的xml文件cannot be open ( class path resource cannot be opened)
查看>>
解决启动springboot项目时localhost一直显示Whitelabel Error Page和@ConfigurationProperties标红
查看>>
springboot项目中的注解 启动项目的方式 解决spring的bean.xml配置不生效 spring的基础JDBC配置
查看>>
mybatis的mapper.xml文件中含有中文注释时运行出错,mybatis配置优化和别名优化 mybatis配置之映射器说明
查看>>
Uncaught (in promise) Error: Request failed with status code 500
查看>>
【错误记录】Error creating bean with name: Unsatisfied dependency expressed through field
查看>>
【笔记】opencv阈值处理 threshold函数 cv2.THRESH_BINARY ,cv2.THRESH_TRUNC) cv2.adaptiveThreshold()
查看>>
pip安装pandas失败Could not find a version that satisfies the requirement pandas
查看>>
【问题记录】pytorch自定义数据集 No such file or directory, invalid index of a 0-dim
查看>>
【笔记】spring的注解回顾,springboot-restful项目结构介绍 springboot-freemarker ⼯程配置详解
查看>>
ubuntu上训练yolov3: Caught ValueError in DataLoader worker process 0. string indices must be integers.
查看>>
在集群服务器进行自定义数据集训练记录过程 TensorBoard logging requires TensorBoard with Python summary writer installed.
查看>>
【问题记录】raise IndexError(‘index {} is out of range‘.format(idx)) index 0 is out of range
查看>>
【问题记录】filters = int(module_def[‘filters‘]) ValueError: invalid literal for int() with base 10: ‘‘
查看>>
Document.visibilityState 页面监听 vue中实现离开页面时计时停止: 停止计时后从上一次开始计时
查看>>
【项目实战】vue-springboot-pytorch前后端结合pytorch深度学习 html打开本地摄像头 监控人脸和记录时间
查看>>
vue-springboot项目 mybatis条件查询结果为null时解决方案 @Param @RequestParam 的参数传递
查看>>