我有一个用JavaScript和PHP编写的小工具,它包含一个URL列表并检查所有这些URL的HTTP状态代码。 我使用curl来检查实际状态。
只要我有漂亮的网址,它就可以很好地工作。我遇到问题,其中有®。当我知道它应该返回301
时,我的工具返回404
。在URL中包含特殊字符的HTTP状态代码
我的猜测是这个'®'被转换成类似%C2
的东西,并导致一个问题。
我知道这可以做到,因为粘贴这个相同的URL here返回301
,因为它应该。
我的PHP卷曲看起来是这样的:
...
if (($curl = curl_init()) == false) {
throw new Exception('curl_init error for url '.$_POST['url'].'.');
}
$header[] = "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5";
$header[] = "Cache-Control: max-age=0";
$header[] = "Connection: keep-alive";
$header[] = "Keep-Alive: 300";
$header[] = "Accept-Charset: iso-8859-1,utf-8;q=0.7,*;q=0.7";
$header[] = "Accept-Language: en-US;q=0.5";
$header[] = "Pragma: ";
curl_setopt($curl, CURLOPT_URL, $_POST['url']);
curl_setopt($curl, CURLOPT_HTTPHEADER, $header);
curl_setopt($curl, CURLOPT_NOBODY, true);
curl_setopt($curl, CURLOPT_AUTOREFERER, true);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_TIMEOUT, 50);
$Cresponse = curl_exec($curl); // execute the curl command
$response['callback']['data'] = $http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);
...
我试图用urldecode()
但这编码整个URL与http://
到http%3A%2F%2F
一起。
任何想法为什么这是导致问题?
我照你的建议做了,Firebug显示的URL正确,但我仍然得到404而不是301 – 6bytes 2012-08-01 13:37:01