Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
检索Twitter';PHP中的sx-RateLimit-Limit_Php_Http_Http Headers_Twitter - Fatal编程技术网

检索Twitter';PHP中的sx-RateLimit-Limit

检索Twitter';PHP中的sx-RateLimit-Limit,php,http,http-headers,twitter,Php,Http,Http Headers,Twitter,每一个我在推特上的请求 但是,我似乎无法使用PHP检索这些内容。有人能告诉我我犯了什么愚蠢的错误吗 我已经以正常的方式设置了curl,并且能够成功地获取和发布请求 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:')); curl_set

每一个我在推特上的请求

但是,我似乎无法使用PHP检索这些内容。有人能告诉我我犯了什么愚蠢的错误吗

我已经以正常的方式设置了curl,并且能够成功地获取和发布请求

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:'));
curl_setopt($ch, CURLOPT_TIMEOUT, 10);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
curl_setopt($ch, CURLOPT_VERBOSE, TRUE);

$response = curl_exec($ch);
$response_info=curl_getinfo($ch);
$erno = curl_errno($ch);
$er = curl_error($ch);
curl_close($ch);
我能够得到一些响应信息,比如http\U代码

$response_info['http_code']
但这行只返回null

//Doesn't bloody work. No idea why!
$rate_limit = $response_info['X-RateLimit-Limit'];
我正在运行PHP版本5.3.10

编辑

这是打印的结果($response\u info)


curl\u getinfo
不返回响应头,只返回关于请求的其他元信息。要检索标题,请将
CURLOPT_标题设置为
true
。这将在输出中包括标题。要将它们与响应主体分开,请执行以下操作:

list($headers, $body) = explode("\n\n", $response, 2);
要分析标题,请再次分解:

$headers = explode("\n", $headers);
foreach ($headers as $header) {
    list($key, $value) = explode(':', $header, 2);
    $headers[trim($key)] = trim($value);
}

echo $headers['X-RateLimit-Limit'];

curl\u getinfo
不返回响应头,只返回关于请求的其他元信息。要检索标题,请将
CURLOPT_标题设置为
true
。这将在输出中包括标题。要将它们与响应主体分开,请执行以下操作:

list($headers, $body) = explode("\n\n", $response, 2);
要分析标题,请再次分解:

$headers = explode("\n", $headers);
foreach ($headers as $header) {
    list($key, $value) = explode(':', $header, 2);
    $headers[trim($key)] = trim($value);
}

echo $headers['X-RateLimit-Limit'];

您是否尝试过使用
var\u dump($response\u info)
查看你从Twitter上实际得到了什么?我有-X-RateLimit-Limit没有出现,嗯。打电话给你返回正确的信息吗?你试过使用
var\u dump($response\u info)
想看看你从Twitter上得到了什么?我有-X-RateLimit-Limit没有出现,嗯。打电话给你返回正确的信息吗?