301="Moved Permanently" Curl php

Asked

Viewed 1,411 times

0

Colleagues.

I am developing a system, but it is giving this error in Curl. Someone knows what can be?

1 answer

4

You probably need to accept redirects.

Add the parameter CURLOPT_FOLLOWLOCATION to Curl:

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

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

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

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

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.