curl请求接口的get和post方法
来源:互联网 发布:pe系统制作软件 编辑:程序博客网 时间:2024/04/25 15:32
get请求方法
<?php
header("Content-type:text/html;charset=utf-8");
/**
* 使用curl 分为4步:
* 第一步,初始化 $ch = curl_init();
* 第二步:进行配置 curl_setopt() //记忆方法:set配置 option选项
* 第三步:执行--发送请求curl_exec()
* 第四步:关闭curl资源 curl_close();
*/
//第一步
$ch = curl_init();
//第二步 配置
$url = "http://www.jxshop.com/index.php/Admin/API/getGoodsByCatAPI/catName/你好啊";
curl_setopt($ch,CURLOPT_URL,$url);
//增加配置,不让结果默认显示,并且可以接收
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//0是默认值,默认把数据展示 1 不展示数据,可以接收 RETURN返回 TRANSFER转义、运输
//第三部 执行
$result = curl_exec($ch);
/*
* 说明:curl在发送请求后,会默认把数据输出,无法接收
*/
$result = json_decode($result,1);
echo "<hr><pre>";
print_r($result);
echo "</pre>";
//第四部 关闭
curl_close($ch);
POST请求方法
/**
* 使用curl 分为4步:
* 第一步,初始化 $ch = curl_init();
* 第二步:进行配置 curl_setopt() //记忆方法:set配置 option选项
* 第三步:执行--发送请求curl_exec()
* 第四步:关闭curl资源 curl_close();
*/
//第一步
$ch = curl_init();
//第二步 配置
$url = "http://www.jxshop.com/index.php/Admin/API/getGoodsByCatAPI";
$data = array('catName'=>"php",'u_id'=>128);//配置post需要传递的数组值,传递多个也行
curl_setopt($ch,CURLOPT_URL,$url);
//增加配置,不让结果默认显示,并且可以接收
curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);//0是默认值,默认把数据展示 1 不展示数据,可以接收 RETURN返回 TRANSFER转义、运输
//添加配置,告诉curl我要用POST方式请求,因为curl发送请求的方式默认是get
curl_setopt($ch,CURLOPT_POST,1);
curl_setopt($ch,CURLOPT_POSTFIELDS,$data);//设置POST需要传递的值
//第三部 执行
$result = curl_exec($ch);
/*
* 说明:curl在发送请求后,会默认把数据输出,无法接收
*/
$result = json_decode($result,1);
echo "<hr><pre>";
print_r($result);
echo "</pre>";
//第四部 关闭
curl_close($ch);
- curl请求接口的get和post方法
- CURL 请求外部接口 GET 和 POST
- curl请求https POST和GET方法
- CURL的get和post请求,简单明了
- 关于Curl的get和post请求
- CURL GET和POST请求
- curl实现HTTP的GET POST方法的请求
- PHP中使用cURL实现Get和Post请求的方法
- PHP中使用cURL实现Get和Post请求的方法
- PHP中使用cURL实现Get和Post请求的方法
- PHP中使用CURL实现Get和Post请求的方法
- PHP中使用cURL实现Get和Post请求的方法
- PHP中使用cURL实现Get和Post请求的方法
- PHP中使用cURL实现Get和Post请求的方法
- PHP中使用CURL实现GET和POST请求的方法以及含义介绍
- Linux 下模拟Http 的get or post请求(curl和wget两种方法)
- Linux 下模拟Http 的get or post请求(curl和wget两种方法)
- PHP中使用cURL实现Get和Post请求的方法
- 【CC2640】Your installer source path contains non-ASCII characters which can corrupt the installation
- string与stringbuffer
- 分布式服务下的交易一致
- 207. Course Schedule
- 夜观星象-深入数据库连接池内部运转原理
- curl请求接口的get和post方法
- mysql建表时的日期类型选择
- 条件结构应用举例
- windows下安装gcc编译器
- string stringbuffer与stringbuilder
- spring中使用context:property-placeholder错误记录
- 基础篇:同步机制之synchronized与ReentrantLock(五)
- SDUT 1730 数字三角形问题
- Android ViewTree and DecorView