2016-10-01 100 views
3

我所做的不和谐一个机器人,我想使请求API使用不和谐API来管理渠道,显示的消息,这种事情。 我已经开始使用Postman来调用API,它工作正常。使用PHP和卷曲

链接到API:https://discordapp.com/developers/docs/intro

然后我试图做使用PHP(WAMP),与卷曲的请求,该请求被发送,但API送我回一个401未授权的响应,尽管我发送了正确的授权标题。 我已经添加了详细选项,以获得更多的相关信息:

* Hostname in DNS cache was stale, zapped 

* Trying 104.16.58.5... 

* Connected to discordapp.com (104.16.58.5) port 443 (#0) 

* ALPN, offering http/1.1 

* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH 

* SSL connection using TLSv1.2/ECDHE-RSA-AES128-GCM-SHA256 

* ALPN, server accepted to use http/1.1 
* Server certificate: 

* subject: OU=Domain Control Validated; OU=PositiveSSL; CN=discordapp.com 

* start date: 2016-03-01 00:00:00 GMT 

* expire date: 2017-03-03 23:59:59 GMT 

* subjectAltName: discordapp.com matched 

* issuer: C=GB; ST=Greater Manchester; L=Salford; O=COMODO CA Limited; CN=COMODO RSA Domain Validation Secure Server CA 

* SSL certificate verify result: unable to get local issuer certificate (20), continuing anyway. 
> GET /api/channels/230833430827499520/messages HTTP/1.1 
Host: discordapp.com 
Accept: */* 
Authorization : Bot <TOKEN> 

< HTTP/1.1 401 UNAUTHORIZED 
< Date: Sat, 01 Oct 2016 01:23:22 GMT 
< Content-Type: application/json 
< Content-Length: 43 
< Connection: keep-alive 
< Set-Cookie: __cfduid=d23fd84fe760ad0b225004284861067621475285002; expires=Sun, 01-Oct-17 01:23:22 GMT; path=/; domain=.discordapp.com; HttpOnly 
< Strict-Transport-Security: max-age=31536000; includeSubDomains 
< Via: 1.1 google 
< Alt-Svc: clear 
< Server: cloudflare-nginx 
< CF-RAY: 2eac1be3385d148b-AMS 
< 
* Connection #0 to host discordapp.com left intact 

我的代码:

$url = 'https://discordapp.com/api/channels/230833430827499520/messages'; 

$ch = curl_init(); 
$f = fopen('request.txt', 'w'); 
curl_setopt_array($ch, array(
    CURLOPT_URL   => $url, 
    CURLOPT_HTTPHEADER  => array('Authorization : Bot <TOKEN>'), 
    CURLOPT_RETURNTRANSFER => 1, 
    CURLOPT_FOLLOWLOCATION => 1, 
    CURLOPT_VERBOSE  => 1, 
    CURLOPT_SSL_VERIFYPEER => 0, 
    CURLOPT_STDERR   => $f, 
)); 
$response = curl_exec($ch); 
fclose($f); 
curl_close($ch); 

我试过的file_get_contents很好,但没有奏效。 我看不到有什么问题,也许SSL证书? 任何thougts?一直在为此挣扎3天,我已经没有想法了。

谢谢!

回答

5

好,我不得不在报头去除第一空间

CURLOPT_HTTPHEADER  => array('Authorization: Bot <TOKEN>') 

代替

CURLOPT_HTTPHEADER  => array('Authorization : Bot <TOKEN>'),