php post获取错误码,使用PHP的POST CURL请求获取错误’没有授权标头’ – envato api...

我开始使用

Enavato API了

到目前为止,我已经创建了一个应用程序,得到了client_id& client_secret并设法从https://api.envato.com/authorization获取代码access_key,之后我使用下面的php代码发出POST卷曲请求

$client_id = '***********';

$client_secret = '***********';

$redirect_uri = urlencode('http://localhost:3000');

if(isset($_GET["code"])) :

$apiUrl = 'https://api.envato.com/token';

$params = array(

'grant_type' => 'authorization_code',

'code' => $_GET["code"],

'redirect_uri' => $redirect_uri,

'client_id' => $client_id,

'client_secret' => $client_secret,

);

$curl = curl_init();

$f = fopen('request.txt', 'w');

curl_setopt($curl, CURLOPT_URL, $apiUrl);

curl_setopt($curl, CURLOPT_POST, 1);

curl_setopt($curl, CURLOPT_VERBOSE, true);

curl_setopt($curl, CURLOPT_HEADER, true);

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);

curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);

curl_setopt($curl, CURLOPT_POSTFIELDS, $params);

curl_setopt($curl, CURLOPT_STDERR, $f);

$result = curl_exec($curl);

fclose($f);

// Check if any error occurred

if(empty($result))

{

// die(curl_errno($curl));

// die(curl_error($curl));

$info = curl_getinfo($curl);

echo '
';

echo 'Took ' . $info['total_time'] . ' seconds to send a request to ' . $info['url'];

echo '
';

var_dump($info);

echo '
';

}

var_dump($result);

// Close handle

curl_close($curl);

endif;

这是request.txt转储

* Hostname was found in DNS cache

* Hostname in DNS cache was stale, zapped

* Trying 107.23.230.180...

* Connected to api.envato.com (107.23.230.180) port 443 (#0)

* TLS 1.2 connection using TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256

* Server certificate: *.envato.com

* Server certificate: RapidSSL SHA256 CA - G3

* Server certificate: GeoTrust Global CA

> POST /token HTTP/1.1

Host: api.envato.com

Accept: */*

Content-Length: 699

Expect: 100-continue

Content-Type: multipart/form-data; boundary=------------------------1a95a06d7b815306

< HTTP/1.1 100 Continue

< HTTP/1.1 400 Bad Request

< Access-Control-Allow-Origin: *

< Cache-Control: no-store

< Content-Type: application/json; charset=utf-8

< Date: Sun, 17 May 2015 17:03:41 GMT

< Pragma: no-cache

* Server nginx/1.7.10 is not blacklisted

< Server: nginx/1.7.10

< set-cookie: connect.sid=s%3ARC9gGye-Txp4KLp67M9ESspXijYoUc8i.pT3jYHvu1WyOsSjwsuQzEsy5hLQlc2QpmHkZRm05pXo; Path=/; HttpOnly

< X-Frame-Options: Deny

< X-Powered-By: Express

< Content-Length: 80

< Connection: keep-alive

* HTTP error before end of send, stop sending

<

* Closing connection 0

最后是错误(以JSON获取)

string(80) “{“error”:”invalid_request”,”error_description”:”No authorization header passed”}”

令人惊讶的是,每件事都与Postman一起使用,我获得了“refresh_token”和“access_token”,并获得了成功的200状态代码.

我知道我错过了一些但却找不到的东西?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值