PHP sends HTTP request GET POST

Source: Internet
Author: User
Tags http post

* CURL Reference Blog: http://www.cnblogs.com/CHEUNGKAMING/p/5717429.html

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 ' = '  Kaifeng ',    ' limit ' = = 6,    ' type ' = '  student '];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 OK
server:apache-coyote/1.1
Pragma:no-cache
Cache-control:no-cache, No-store , Max-age=0
Expires:thu, 1970 00:00:00 GMT
Content-type:application/json;charset=utf-8
Content-language:zh
transfer-encoding:chunked
Date:sun, Jul 2018 09:30:23 GMT

{"Teacherlist": [{"id": $, "name": "Du Ying", "url": null, "IMG": "./kaifeng33_img/studentview/4.jpg", "School": "Kaifeng 33", " DateTime ": null," Intro ":" 33 Outstanding Student representative Speech "," Content ": null},{" id ":" "Name": "Zhu Tong", "url": null, "IMG": "./kaifeng33_img/ Studentview/3.jpg "," School ":" Kaifeng 33 "," datetime ": null," Intro ":" First 27 shifts "," content ": null},{" id ": $," name ":" Zhangmeng "," url ": null," IMG ":"./kaifeng33_img/studentview/2.jpg "," School ":" Kaifeng 33 "," datetime ": null," Intro ":" Class 36 "," content ": null},{"id": +, "name": "Week Dream Cold", "url": null, "IMG": "./kaifeng33_img/studentview/1.jpg", "School": "Kaifeng 33", "datetime": NULL, "Intro": "Class 36", "Content": null},{"id": "Name": "Cheng Garden", "url": null, "IMG": "./publish/students/kaifeng5/04.jpg" , "school": "Kaifeng V", "datetime": null, "Intro": "15 session high three or four", "Content": null},{"id": +, "name": "Zhu Chong", "url": null, "IMG": ". Publish/students/kaifeng5/03.jpg "," School ":" Kaifeng V "," datetime ": null," Intro ":" 15 session high three or four Zhu Chong "," 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.1host:www.tfjyzx.comconnect Ion:keep-alivecontent-length:48pragma:no-cachecache-control:no-cacheaccept:application/json, Text/javascript, * * *; q=0.01origin:http://www.tfjyzx.comx-requested-with:xmlhttprequestuser-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.36content-type:application /x-www-form-urlencoded; Charset=utf-8referer:http://www.tfjyzx.com/login.jspaccept-encoding:gzip, deflateaccept-language:en-us,en;q=0.9 , Zh-cn;q=0.8,zh;q=0.7,ja;q=0.6cookie:experience=show; jsessionid=c63bf22874a3b791f212cfcbaffae432 "; $header = explode (" \ n ", $s);//http://jp2.php.net/manual/en/ Function.curl-setopt.phpcurl_setopt_array ($ch, [curlopt_url = ' http://118.190.150.189/student/login ',//TRUE T    O include the header in the output. Curlopt_header = 1, Curlopt_returNtransfer = 1,//TRUE to do a regular HTTP POST.    This POST was 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 = $head    er, curlopt_postfields = ' username=xxxxx150835&pwd=123456&captcha=&count=1 ',//Phone number/* Curlopt_postfields = [' username ' = ' gmy12345 ', ' pwd ' = ' 123456 ', ' captcha ' and ' = ' ', ' count ' = 1], curlopt_encoding = ' gzip, deflate ', Curlopt_cookie = ' experience=show; jsessionid=c63bf22874a3b791f212cfcbaffae432 ', */curlopt_timeout = 5]); $data = Curl_exec ($ch); Curl_close ($ch); EC Ho $data. Php_eol;

  

http/1.1 OK
server:apache-coyote/1.1
Set-cookie:jsessionid=ac471f40cdc460d6d7c14baacae21ed5; path=/; HttpOnly
Content-type:application/json;charset=utf-8
content-length:118
Date:sun, Jul 2018 09:32:30 GMT

{"Result": 1, "cause": "Login Successful!" "," School ":" Puyang the Middle School "," SessionId ":" Ac471f40cdc460d6d7c14baacae21ed5 "}

PHP sends HTTP request GET POST

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.