J'ai une url qui contient toutes les informations dans l'url (nom d'utilisateur/mot de passe/contenu ect)php curl - url d'accès via la réponse du navigateur: 200 url d'accès via curl réponse: 401?
Si je visite l'URL dans mon navigateur, j'obtiens une réponse positive.
si je visite l'url par boucle je reçois 401.
Il n'y a pas d'authentification sur l'URL.
Ce qui pourrait être à l'origine de cela?
code:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'http://mconnect.co.nz/v1/sendmessage?appname=app&pass=pass&msgclass=test&msgid=6&body=Some+Content&to=02712345678');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $mconnect[$index]['app_name'] . ":" . $mconnect[$index]['app_pass']);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US) AppleWebKit/534.12 (KHTML, like Gecko) Chrome/9.0.587.0 Safari/534.12');
curl_setopt($ch, CURLOPT_FAILONERROR, true);
curl_setopt($ch, CURLOPT_HTTPGET, true);
curl_setopt($ch, CURLOPT_POST, false);
if(curl_exec($ch) === false)
echo 'fail: '.curl_error($ch);
Mise à jour ... Etrange ...
Ainsi,
Je construis mon URL par mConnect $ [$ index ] ['url']. '?' . http_build_query ($ url);
qui me donne l'URL ci-dessus.
Ainsi,
Si je
$url = $mconnect[$index]['url'] . '?' . http_build_query($url);
curl_setopt($ch, CURLOPT_URL, $url);
Je reçois le 401.
Mais,
Si je puis echo $mconnect[$index]['url'] . '?' . http_build_query($url);
Je reçois
donc si je puis faire
$url = 'http://mconnect.co.nz/v1/sendmessage?appname=app&pass=pass&msgclass=test&msgid=6&body=Some+Content&to=02712345678';
curl_setopt($ch, CURLOPT_URL, $url);
Ensuite, il fonctionne ...
des idées?
êtes-vous sûr que vous faites HTTP après/obtenir l'aide cURL ? –
Juste ajouté le code – Hailwood