发送php autorization post请求

时间:2017-02-07 03:01:46

标签: php curl

我试着发送这个卷曲:

 curl -H "Authorization: Bearer <access token>" --data-urlencode "model=" --data-urlencode "url=http://assets.mojang.com/SkinTemplates/steve.png" https://api.mojang.com/user/profile/<uuid>/skin

我试过了:

 $url = 'https://api.mojang.com/user/profile/myuuid/skin';
 $skin_url = "http://assets.mojang.com/SkinTemplates/steve.png";
 $accesstoken = "myacessToken";
 $crl = curl_init();
 $headr = array();

 $headr[] = 'Host: api.mojang.com';
 $headr[] = 'User-Agent: curl/7.49.0';
 $headr[] = 'Accept: */*';
 $headr[] = 'Authorization: Bearer '.$accesstoken;
 $headr[] = 'Content-Length: 69';
 $headr[] = 'Content-Type: application/x-www-form-urlencoded';

 $ch = curl_init();

 curl_setopt($ch, CURLOPT_URL, $url);
 curl_setopt($ch, CURLOPT_HTTPHEADER,$headr);
 curl_setopt($ch, CURLOPT_POST, true);
 curl_setopt($ch, CURLOPT_POSTFIELDS,
     "model=&url=http%3A%2F%2Fassets.mojang.com%2FSkinTemplates%2Fsteve.png");

 $server_output = curl_exec ($ch);
 var_dump($server_output);
 curl_close ($ch);

我的输出:

   bool(false)

我确定我的访问令牌是有效的和uuid。我做错了什么?

感谢

1 个答案:

答案 0 :(得分:1)

尝试使用app.get('/user', isLoggedIn, function(req, res) { res.render('user', { user : req.user, timeZone: timeZones(), appointment : new Appointment({ phoneNumber: "", notification: '', timeZone: "", time:''}), loggedIn: true, // get the user out of session and pass to template layout: 'home' }); });