I have this script:

$server = "https://server.com";
$fileType = "/api/table.json?";
$uName = "bart";
$pWord = "XXXXXX";
$url = "content=devices&id=2672&output=xml&columns=group,name&username=" . $uName . "&userhash=" . $pWord;

$request = $server . $fileType . $url;
echo file_get_contents($request);

when i call it via php -f file.php I get this error:

failed to open stream: HTTP request failed! HTTP/1.1 401 Unauthorized

if i load the url into browser, it works as expected. any thoughts?


Article Comments

Hi,
in your variable $url please try using either the parameter passhash or password but not userhash. Corrected version below:

$url = "content=devices&id=2672&output=xml&columns=group,name&username=" . $uName . "&passhash=" . $pWord;

(use password as parameter if you are using the password to authenticate)
Does that work?


Jul, 2014 - Permalink

passhash worked. thank you.


Jul, 2014 - Permalink