我有一个用 JavaScript 和 PHP 编写的小工具,它获取 URL 列表并检查所有 URL 的 HTTP 状态代码。我使用 curl 来检查实际状态。
只要我有不错的 URL,它就可以很好地工作。我遇到了包含®的 URL 的问题。404当我知道它应该返回时,我的工具会返回301。
我的猜测是这个“®”正在被转换为类似的东西%C2并导致问题。
我知道这是可以做到的,因为在此处粘贴相同的 URL 会返回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://to一起编码http%3A%2F%2F。
知道为什么这个 ® 会导致问题吗?