curl请求重定向到限制本地服务器上的页面

时间:2020-05-11 04:13:25

标签: php laravel curl

我有放置(更新)数据的代码,该代码适用于实时网络上的postman,但是如果我在localserver(xampp)上进行测试,它将重定向到限制页面。这是我的日志错误

<html>
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="refresh" content="0;url='http://localhost:8000/api/restrict'" />

        <title>Redirecting to http://localhost:8000/api/restrict</title>
    </head>
    <body>
        Redirecting to <a href="http://localhost:8000/api/restrict">http://localhost:8000/api/restrict</a>.
    </body>
</html> 

这是我的curl代码:

    $url = 'http://localhost:8000/api/some-page/' . $id;
    $user = $this->checkauthorization($request->header('Authorization'));
    $token = $user->access_token;
    $ch = curl_init($url);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');
    // common description bellow
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) .   '(cookie cracker yummy)');
    curl_setopt($ch, CURLOPT_COOKIEFILE, dirname(__FILE__) .   '(cookie cracker yummy)');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
    curl_setopt($ch, CURLOPT_TIMEOUT, (120));
    curl_setopt($ch, CURLOPT_HTTPHEADER, array(
      "Authorization: Bearer " . $token
    ));

    $response = curl_exec($ch);
    // dd($response);
    $header = curl_getinfo($ch);
    // 200? 404? or something?
    $error_no = curl_errno($ch);
    $error = curl_error($ch);
    $coderespon = curl_getinfo($ch, CURLINFO_HTTP_CODE);
    curl_close($ch);
    $data['data'] = json_decode($response, true);
    $data['code'] = $coderespon;
    return $data;

此错误是我的代码或我的xampp配置, 谢谢您的帮助

0 个答案:

没有答案