下面看一个利用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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

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.
