CURL returns code 303

Asked

Viewed 96 times

0

I have the following code:

$fields = array('usuario'=>urlencode($jm->Login),'senha'=>$jm->Senha);//url-ify the data for the POST
$fields_string = '';
foreach($fields as $key=>$value) {
$fields_string .= $key.'='.$value.'&'; }
$url = "https://www.sitecliente.com.br/validar/";
$ch = curl_init();//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL,$url);
curl_setopt($ch,CURLOPT_POST,count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS,$fields_string);//execute post
curl_setopt($ch, CURLOPT_MAXREDIRS, 5);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 1);
$result = curl_exec($ch);//close connection
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
echo "STATUS: ";
print_r($status);
curl_close($ch);

The goal is to click on a link within our system, to be directed to an external system. When we do this, it validates, but the page is empty. When you print the status, it returns the message: STATUS: 303.

I found that this error may be because we are using the POST and we should use the GET. How I would do this?

1 answer

0

To send by GET method:

curl_setopt($ch, CURLOPT_POST, 0);

Alternatively you can use CURLOPT_CUSTOMREQUEST

curl_setopt($curl_handle, CURLOPT_CUSTOMREQUEST, 'GET');

I remember having answered something about CURL a few months ago, so I did a search and to my surprise I found a question of yours that I answered: As I pass parameters through Curl?

This link clarifies the same doubts you are posting here again, so I thought it relevant to post.

Returning to the subject of the current question, note that this does not make sense:

curl_setopt($ch,CURLOPT_POST,count($fields));

The value is boolean true/false or 1/0 where 1 is true and 0 is false. Anyway, this is also explained in the link of the question asked in April.

One more remark, I’m not guaranteeing that the http 303 status will be solved because the problem may have a different cause than what was commented on the question.

  • Hi Daniel. I changed the code, but the problem remains.

  • @Fox.11, I can’t do anything with vague information.

  • Hello Daniel, the information I can give you is that. I would like to access an external system via post, but it validates correctly, but does not direct and when I print the status, returns the 303. I don’t know if it’s the way I’m programming Curl, so I’d like help...

  • Yes, that’s very clear. But there’s nothing I can do. I don’t know how you are doing, how is the code of the page that receives the data, how you tried to make the changes, what are the conditions of the environments, etc.. Anyway, these are the details. I can try to "kick" dozens of options to solve but this is unproductive and out of focus, making this question a technical support service.

Browser other questions tagged

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