Php curl extension can help us quickly implement HTTP requests.
When using the doubanoauth login interface, we need to send such an http request:
The code is as follows: |
Copy code |
GET/v2/user /~ I HTTP/1.1 Host: https://api.douban.com Authorization: Bearer a14afef0f66fcffce3e0fcd2e34f6ff4 |
Run the following command in the command line:
The code is as follows: |
Copy code |
Curl https://api.douban.com/v2/user /~ Me" -H "Authorization: Bearer a14afef0f66fcffce3e0fcd2e34f6ff4" |
Php curl sends Authorization HTTP request
Http curl:
The code is as follows: |
Copy code |
$ 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 ); |
If you need http curl to implement GET requests, see the following:
Http curl:
The code is as follows: |
Copy code |
$ 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/'.20.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 ); |
Then it processes the received results. Generally, the interface class will return JSON or XML, and the collection class will directly filter the HTML content.