* 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的更多相关文章

  1. curl 发送post请求

    curl 发送post请求 curl -X POST "http://localhost:8080/usr3?id=1&name=3&departmentId=2" ...

  2. curl 发送json请求

    curl 发送json请求 这个是在cmd环境下的输入:注意{\"userName\":\"helo\",\"id\":1}中间不能有空格 ...

  3. linux shell中curl 发送post请求json格式问题

    今天在linux中使用curl发送一个post请求时,带有json的数据,在发送时发现json中的变量没有解析出来 如下 curl -i -X POST -H 'Content-type':'appl ...

  4. 每天一个linux命令13之curl发送http请求

    一.get请求 curl "http://www.baidu.com"  如果这里的URL指向的是一个文件或者一幅图都可以直接下载到本地 curl -i "http:// ...

  5. [转]使用 curl 发送 POST 请求的几种方式

    HTTP 的 POST 请求通常是用于提交数据,可以通过这篇文章来了解各种提交方式:四种常见的 POST 提交数据方式.做 Web 后端开发时,不可避免地要自己给自己发请求来调试接口,这里要记录的内容 ...

  6. curl发送post请求,统计响应时间

    curl  -o /dev/null -s -w %{time_namelookup}::%{time_connect}::%{time_starttransfer}::%{time_total}:: ...

  7. linux用curl发送post请求

    1.curl -X POST “http://XXXXXXX”这种请求方式参数直接写在URL里面的,而不是body

  8. 一个常用的通过curl发送HTTP请求的函数

    function: function curl_get($url, $params) { return curl_http($url, $params, 'GET'); } function curl ...

  9. php curl 发送post请求

    PHP curl_init函数 resource curl_init ([ string $url = NULL ] ) 初始化一个新的会话,返回一个cURL句柄,供curl_setopt(), cu ...

  10. curl 发送 post 请求

    curl -i -X POST -H 'Content-type':'application/json' -d '{"keyWord":"雅诗兰黛"," ...

随机推荐

  1. MySQL Mac 终端环境变量配置

    MySQL Mac 终端环境变量配置 这里安装的是mysql-8.0.26-macos11-x86_64,M1Mac,原本打算安装arm64版本,但一直安装不了,就装了x86版本 安装完成MySQL之 ...

  2. 我的微服务之路,看我搭建dapr趟过的坑

    前言 自从上周看了一个Dapr的视频,知道原来自己离微服务很近,简直触手可及. 心痒痒好久了,不动手实践验证一下简直是寝食难安.先是看官网的文档,可能是因为被墙了,有些网址是不能访问的,那安装搭建环境 ...

  3. NOIP 模拟 $29\; \rm 完全背包问题$

    题解 \(by\;zj\varphi\) 一道 \(\rm dp\) 题. 现将所有种类从小到大排序,然后判断,若最小的已经大于了 \(\rm l\),那么直接就是一个裸的完全背包,因为选的总数量有限 ...

  4. Thread类中yield方法

    Yield方法可以暂停当前正在执行的线程对象,让其他有相同优先级的线程执行.它是一个静态方法而且只保证当前线程放弃CPU占用而不能保证其它线程一定能占用CPU,执行yield()的线程有可能在进入到暂 ...

  5. 《深入理解Spring Cloud与微服务构建》学习笔记(二十)~配置中心Spring Cloud Config

    本例重新创建项目,构建一个空的mavan工程. 一.Config Server 从本地读取配置文件 新建一个moudle config_server ,pom添加依赖   <dependency ...

  6. 消除不受信任的HTML (来防止XSS攻击)

    问题 在做网站的时候,经常会提供用户评论的功能.有些不怀好意的用户,会搞一些脚本到评论内容中,而这些脚本可能会破坏整个页面的行为,更严重的是获取一些机要信息,此时需要清理该HTML,以避免跨站脚本cr ...

  7. Navicat查询出的数据有时候不能更改?

    Navicate查出数据只读,一种情况是查询没带出主键(唯一索引),无法更新数据

  8. Java File常见用法

    一.构造方法 File(File parent, String child) 从父抽象路径名和子路径名字符串创建新的 File实例. File(String pathname) 通过将给定的路径名字符 ...

  9. 关于Mybatis中表中字段名和POJO中字段名不同的解决方法

    项目结构: POJO中: package com.domain; /** * @author mzy * 定义orders表对应的实体类 */ public class Order { /** * C ...

  10. IDEA快捷键命令

    Ctrl+Alt+T   IDEl 抛异常快捷键ctrl +o  继承类时 继承方法快捷键Ctrl+Alt+左右方向键  回到上次光标停留的地方ALt +left/right  快速切换两个页面ctr ...