PHP CURL Authentication error code 302 -


i need send post request authentication.

i try code error 302.

$url = "https://wifinext.internavigare.com/prepagataanagrafica/creautente/"; $username = 'myuser'; $password = 'mypassword'; // create new curl resource $ch= curl_init($url);  // post request, using application/x-www-form-urlencoded type curl_setopt($ch, curlopt_post, true); // credentials curl_setopt($ch, curlopt_userpwd, "$username:$password"); // returns response instead of displaying curl_setopt($ch, curlopt_returntransfer, 1);  curl_setopt($ch, curlopt_ssl_verifypeer, 0); curl_setopt($ch, curlopt_ssl_verifyhost, 0);  //curl_setopt($ch, curlopt_followlocation, true);  //set post fields curl_setopt($ch, curlopt_postfields, "prepagata_codice=test&prepagata_password=123456");  // request, response text available in $response $response = curl_exec($ch); // status code, example, 200 $statuscode = curl_getinfo($ch, curlinfo_http_code);  //show response echo $statuscode; echo $response;  // close curl resource, , free system resources curl_close($ch); 

i see answer use curlopt_followlocation or cookies , try cannot figure out how do. i'm pull out hair. please appreciated.

status code 302 means url redirects url. set curl option curlopt_followlocation true follow redirect.

curl_setopt($ch, curlopt_followlocation, 1); 

Comments

Popular posts from this blog

javascript - Create a stacked percentage column -

Optimising Firebase database by automatically overwriting data -

javascript - Angular UI-Grid customTemplate directive causing rows to load slowly/? -