下面看一个利用PHP CURL 实现HTTP请求豆瓣OAuth登录接口时的一个例子,希望此例子对各位同学会带来帮助哦
PHP CURL 扩展可以帮助我们快速实现HTTP请求。
在使用豆瓣OAuth登录接口时,我们需要发送这样的HTTP REQUEST 请求:
代码如下 | 复制代码 |
GET /v2/user/~me HTTP/1.1 |
在命令行中我们这样执行:
代码如下 | 复制代码 |
curl "https://api.douban.com/v2/user/~me" |
PHP CURL 发送 Authorization HTTP 请求
HTTP CURL 执行 POST 方法:
代码如下 | 复制代码 |
$crl = curl_init(); $headr = array(); $headr[] = 'Authorization: '.$douban_user_name.' '.$accesstoken; curl_setopt($crl, CURLOPT_HTTPHEADER,$headr); curl_setopt($crl, CURLOPT_POST,true); $rest = curl_exec($crl); curl_close($crl); print_r($rest); |
如果需要HTTP CURL实现GET请求,请看下面:
HTTP CURL 执行 GET 方法:
代码如下 | 复制代码 |
$header = array(); $header[] = 'Authorization: '.$data->douban_user_name.' '.$data->access_token; $ch = curl_init(); www.111cn.net curl_setopt($ch, CURLOPT_HTTPHEADER, $header); curl_setopt($ch, CURLOPT_URL, 'https://api.douban.com/v2/user/'.$data->douban_user_id); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_BINARYTRANSFER, true); $response = curl_exec($ch); curl_close($ch); print_r($response); |
然后就是处理接收到的结果,一般接口类会返回JSON或者XML,采集类就直接过滤HTML的内容即可。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

Dreamweaver Mac version
Visual web development tools

Dreamweaver CS6
Visual web development tools