301="Moved Permanently" curl php

0

Colleagues.

I'm developing a system, but it's giving this error in curl. Does anyone know what it can be?

    
asked by anonymous 30.04.2016 / 00:16

1 answer

3

You probably need to accept redirects.

Add the CURLOPT_FOLLOWLOCATION parameter to the Curl:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

This will enable you to follow the "Location:" header of your request, so Curl will follow the redirection provided by error 301.

You can set the amount of redirects, using CURLOPT_MAXREDIRS next to Curl, for example:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);

CURLOPT_MAXREDIRS has the function of limiting the number of redirects, in this case 5, but can be changed.

You can also use CURLOPT_AUTOREFERER to update the "Referer:" for the last "Location:" obtained, may be necessary in some cases.     

30.04.2016 / 01:00