Ich habe eine URL, die alle Informationen in der URL enthält (Benutzername/Passwort/Inhalt ect)php curl - Zugriff URL über Browser Antwort: 200 Zugriff URL über curl Antwort: 401?
Wenn ich die URL in meinem Browser besuche bekomme ich eine erfolgreiche Antwort.
Jedoch Wenn ich die URL durch curl besuchen komme ich 401.
Es gibt keine Authentifizierung auf der URL ist.
Was könnte das verursachen?
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);
Update ... Seltsam ...
So
Ich baue meine url durch $ MConnect [$ index ] ['url']. "?" . http_build_query ($ url);
was mir die obige URL gibt.
So
Wenn ich
$url = $mconnect[$index]['url'] . '?' . http_build_query($url);
curl_setopt($ch, CURLOPT_URL, $url);
ich die 401.
Aber
Wenn ich dann echo $mconnect[$index]['url'] . '?' . http_build_query($url);
bekomme ich
so, wenn ich
dann$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);
Dann funktioniert es ...
irgendwelche Ideen?
sind Sie sicher, dass Sie tun, HTTP-Post/get mit cURL zu bauen ? –
Nur Code hinzugefügt – Hailwood