网站首页 > 技术文章 正文
$data = array("name" => "Hagrid", "age" => "36");
$data_string = json_encode($data);//提交的JSON数据
$ch = curl_init('http://api.local/rest/users');
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");//POST方式
curl_setopt($ch, CURLOPT_POSTFIELDS,$data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = curl_exec($ch);
PHP模拟提交POST,数据为JSON数据的源代码
这个POST请求可以扩展带COOKIE进行请求,现在大多数网站都的请求方式都变成这一种了,通过这段代码可解决大部分网站请求问题。
欢迎大家评论区交流!
猜你喜欢
- 2024-10-03 Spring Boot API 如何获得 JSON 数据
- 2024-10-03 大白话 golang 教程-20-使用 RPC 远程调用
- 2024-10-03 软件更新速递:Go发布1.15版本,这些新特性抢先看
- 2024-10-03 掌握 Postman 工具发送请求的简易教程
- 2024-10-03 python接口自动化-Json数据处理(python接口自动化流程)
- 2024-10-03 python接口自动化(八)--发送post请求的接口(详解)
- 2024-10-03 Flink 在唯品会的实践(唯品会 分析)
- 2024-10-03 web开发之-ajax的基本使用(处理json数据)
- 2024-10-03 Java POST JSON 数据处理异常 (code 160)): was expecting double-quote
- 2024-10-03 使用Postman发送POST请求的指南(postman如何发送post请求)
- 02-21走进git时代, 你该怎么玩?_gits
- 02-21GitHub是什么?它可不仅仅是云中的Git版本控制器
- 02-21Git常用操作总结_git基本用法
- 02-21为什么互联网巨头使用Git而放弃SVN?(含核心命令与原理)
- 02-21Git 高级用法,喜欢就拿去用_git基本用法
- 02-21Git常用命令和Git团队使用规范指南
- 02-21总结几个常用的Git命令的使用方法
- 02-21Git工作原理和常用指令_git原理详解
- 最近发表
- 标签列表
-
- cmd/c (57)
- c++中::是什么意思 (57)
- sqlset (59)
- ps可以打开pdf格式吗 (58)
- phprequire_once (61)
- localstorage.removeitem (74)
- routermode (59)
- vector线程安全吗 (70)
- & (66)
- java (73)
- org.redisson (64)
- log.warn (60)
- cannotinstantiatethetype (62)
- js数组插入 (83)
- resttemplateokhttp (59)
- gormwherein (64)
- linux删除一个文件夹 (65)
- mac安装java (72)
- reader.onload (61)
- outofmemoryerror是什么意思 (64)
- flask文件上传 (63)
- eacces (67)
- 查看mysql是否启动 (70)
- java是值传递还是引用传递 (58)
- 无效的列索引 (74)