php CURL 发送http请求 GET POST
* CURL
http://www.php.net/manual/en/book.curl.php
http://jp2.php.net/manual/en/function.curl-setopt.php
GET:
<?php
/**
* Created by PhpStorm.
* User: Mch
* Date: 7/8/18
* Time: 16:02
*/
$ch = curl_init(); $url = 'http://www.tfjyzx.com/news/listTeacherByArea';
$params = [
'area' => '开封市',
'limit' => 6,
'type' => '学生'
]; function get_url($url, $params) {
$a = [];
foreach ($params as $name => $value) {
$a[] = $name .'=' .urlencode($value);
}
$url .= '?'.implode('&', $a);
return $url;
} $url = get_url($url, $params);
echo $url.PHP_EOL; curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_HEADER => 1,
CURLOPT_RETURNTRANSFER => 1
]); $data = curl_exec($ch);
curl_close($ch); echo $data.PHP_EOL;
http://www.tfjyzx.com/news/listTeacherByArea?area=%E5%BC%80%E5%B0%81%E5%B8%82&limit=6&type=%E5%AD%A6%E7%94%9F
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Pragma: no-cache
Cache-Control: no-cache, no-store, max-age=0
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Content-Type: application/json;charset=UTF-8
Content-Language: zh
Transfer-Encoding: chunked
Date: Sun, 08 Jul 2018 09:30:23 GMT
{"teacherList":[{"id":43,"name":"杜姝臻","url":null,"img":"./kaifeng33_img/studentView/4.jpg","school":"开封市33中","datetime":null,"intro":"三十三中优秀学生代表发言","content":null},{"id":42,"name":"朱彤","url":null,"img":"./kaifeng33_img/studentView/3.jpg","school":"开封市33中","datetime":null,"intro":"初二七班","content":null},{"id":41,"name":"张梦岩","url":null,"img":"./kaifeng33_img/studentView/2.jpg","school":"开封市33中","datetime":null,"intro":"三六班","content":null},{"id":40,"name":"周梦寒","url":null,"img":"./kaifeng33_img/studentView/1.jpg","school":"开封市33中","datetime":null,"intro":"三六班","content":null},{"id":20,"name":"程园林","url":null,"img":"./publish/students/kaifeng5/04.jpg","school":"开封市五中","datetime":null,"intro":"15届高三四","content":null},{"id":19,"name":"朱崇","url":null,"img":"./publish/students/kaifeng5/03.jpg","school":"开封市五中","datetime":null,"intro":"15届高三四 朱崇","content":null}]}
POST:
<?php
/**
* Created by PhpStorm.
* User: Mch
* Date: 7/8/18
* Time: 16:19
*/
$ch = curl_init(); $s = "POST /student/login HTTP/1.1
Host: www.tfjyzx.com
Connection: keep-alive
Content-Length: 48
Pragma: no-cache
Cache-Control: no-cache
Accept: application/json, text/javascript; q=0.01
Origin: http://www.tfjyzx.com
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3396.99 Safari/537.36
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Referer: http://www.tfjyzx.com/login.jsp
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7,ja;q=0.6
Cookie: experience=show; JSESSIONID=C63BF22874A3B791F212CFCBAFFAE432";
$header = explode("\n", $s); // http://jp2.php.net/manual/en/function.curl-setopt.php
curl_setopt_array($ch, [
CURLOPT_URL => 'http://118.190.150.189/student/login',
// TRUE to include the header in the output.
CURLOPT_HEADER => 1,
CURLOPT_RETURNTRANSFER => 1,
// TRUE to do a regular HTTP POST. This POST is the normal
// application/x-www-form-urlencoded kind, most commonly used by HTML forms.
CURLOPT_POST => 1,
CURLOPT_BINARYTRANSFER => 1,
CURLOPT_SAFE_UPLOAD => 1,
CURLOPT_HTTPHEADER => $header,
CURLOPT_POSTFIELDS => 'username=XXXXX150835&pwd=123456&captcha=&count=1', // phone number
/*
CURLOPT_POSTFIELDS => [
'username' => 'gmy12345',
'pwd' => '123456',
'captcha' => '',
'count' => 1
],
CURLOPT_ENCODING => 'gzip, deflate',
CURLOPT_COOKIE => 'experience=show; JSESSIONID=C63BF22874A3B791F212CFCBAFFAE432',
*/
CURLOPT_TIMEOUT => 5
]); $data = curl_exec($ch);
curl_close($ch); echo $data . PHP_EOL;
HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Set-Cookie: JSESSIONID=AC471F40CDC460D6D7C14BAACAE21ED5; Path=/; HttpOnly
Content-Type: application/json;charset=UTF-8
Content-Length: 118
Date: Sun, 08 Jul 2018 09:32:30 GMT
{"result":1,"cause":"登录成功!","school":"濮阳市第八中学","sessionId":"AC471F40CDC460D6D7C14BAACAE21ED5"}
Sample Request Header:
Accept:*/*
Accept-Encoding:gzip, deflate, sdch
Accept-Language:zh-CN,zh;q=0.8,ja;q=0.6,en;q=0.4,ko;q=0.2,en-US;q=0.2,vi;q=0.2,fr;q=0.2,la;q=0.2
Connection:keep-alive
Host:192.168.10.137:9999
Origin:http://zhanghum:8088
Referer:http://zhanghum:8088/admin/index.html
User-Agent:Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36
Sample Response header:
Access-Control-Allow-Credentials:true
Access-Control-Allow-Origin:http://zhanghum:8088
Content-Encoding:gzip
Content-Type:application/json
Date:Mon, 16 Jul 2018 02:03:12 GMT
Transfer-Encoding:chunked
Vary:Accept-Encoding
php CURL 发送http请求 GET POST的更多相关文章
- curl 发送post请求
curl 发送post请求 curl -X POST "http://localhost:8080/usr3?id=1&name=3&departmentId=2" ...
- curl 发送json请求
curl 发送json请求 这个是在cmd环境下的输入:注意{\"userName\":\"helo\",\"id\":1}中间不能有空格 ...
- linux shell中curl 发送post请求json格式问题
今天在linux中使用curl发送一个post请求时,带有json的数据,在发送时发现json中的变量没有解析出来 如下 curl -i -X POST -H 'Content-type':'appl ...
- 每天一个linux命令13之curl发送http请求
一.get请求 curl "http://www.baidu.com" 如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地 curl -i "http:// ...
- [转]使用 curl 发送 POST 请求的几种方式
HTTP 的 POST 请求通常是用于提交数据,可以通过这篇文章来了解各种提交方式:四种常见的 POST 提交数据方式.做 Web 后端开发时,不可避免地要自己给自己发请求来调试接口,这里要记录的内容 ...
- curl发送post请求,统计响应时间
curl -o /dev/null -s -w %{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}:: ...
- linux用curl发送post请求
1.curl -X POST “http://XXXXXXX”这种请求方式参数直接写在URL里面的,而不是body
- 一个常用的通过curl发送HTTP请求的函数
function: function curl_get($url, $params) { return curl_http($url, $params, 'GET'); } function curl ...
- php curl 发送post请求
PHP curl_init函数 resource curl_init ([ string $url = NULL ] ) 初始化一个新的会话,返回一个cURL句柄,供curl_setopt(), cu ...
- curl 发送 post 请求
curl -i -X POST -H 'Content-type':'application/json' -d '{"keyWord":"雅诗兰黛"," ...
随机推荐
- MATLAB—信号与系统中的应用
文章目录 一. 理论知识 1.线性系统的响应 2.微分方程的解 Ⅰ.经典解 Ⅱ.完全响应 3.零输入响应 4.零状态响应 5.冲激响应 6.阶跃响应 7.卷积求零状态响应 二.连续信号的MATLAB描 ...
- comm tools
RTL:寄存器传输级别 LRM:语言参考手册 FSM:有限状态机 EDIF:电子数据交换格式 LSO:库搜索目录 XCF:XST 约束条件 1. par -ol. high 命令总是 '-'开头,参 ...
- 源码安装nginx开启SSL功能
编译安装nginx的环境 yum -y install gcc zlib zlib-devel pcre-devel openssl openssl-devel 下载nginx安装包 cd /usr/ ...
- final、finally与finalize的区别?
一.final.finally与finalize的区别 final:final是一个修饰符,可以修饰类,方法和变量.final修饰类表示类不能被其它类继承,并且该类中的所有方法都会隐式的被final修 ...
- nodejs根据word模板生成文档
这里使用的模块是 docx-templates,直接npm安装即可[方法二:https://www.cnblogs.com/vichang/p/10416449.html] 1,模板文件 +++QU ...
- 学习Java的9张思维导图
转自:https://blog.csdn.net/aitaozi11/article/details/79652943 网上搜集了java的学习思维导图,分享给大家. 01.Java程序设计(基础) ...
- Acwing 883高斯消元法的运用
Acwing 883高斯消元法的运用 解线性方程组 Acwing 883 输入一个包含 n 个方程 n 个未知数的线性方程组. 方程组中的系数为实数. 求解这个方程组. 下图为一个包含 m 个方程 n ...
- [题解] Luogu P5446 [THUPC2018]绿绿和串串
[题解] Luogu P5446 [THUPC2018]绿绿和串串 ·题目大意 定义一个翻转操作\(f(S_n)\),表示对于一个字符串\(S_n\), 有\(f(S)= \{S_1,S_2,..., ...
- IDEA第三方jar包引入的三种方法(专治IDEA2020.1.1的坑)
一: 二: 三:
- 微信小程序 转盘抽奖 倒计时 整点
xml: <view id="luckdraw_box"> <view id="luckdraw_back"> <image st ...