简体   繁体   中英

301 Moved Permanently PHP Laravel

Hi I'm trying to get data from anther site so I used

    $url = 'MY_URL' . $route . '/' . $id;
    $ch = curl_init($url);

    curl_setopt($ch, CURLOPT_HTTPHEADER, array('url: ACCESS_URL', 'token: TOKEN'));
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_POST, $type);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;

so I get 301 Moved Permanently output I works fine on local machine put after uploading I got that error ,any suggestions

我的问题是缺少组件curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

您需要专门告诉cURL遵循重定向:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM