The following code is working on my Windows machine but the same code does not work on my server. My server platform is Linux.
The error I get is:
Status Code: 401 Result: HTTP/1.1 401 Unauthorized
My code:
<?php
try {
$username = 'mXXXX';
$password = 'SyXXX';
$URL = 'http://svt-srv-nav.synovergetech.com:7047/DynamicsNAV90/WS/SMCSPL/Page/Customer';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $URL);
curl_setopt($ch, CURLOPT_TIMEOUT, 30); //timeout after 30 seconds
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURLOPT_USERPWD, "$username:$password");
$result = curl_exec($ch);
$status_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); //get status code
curl_close($ch);
//var_dump($result);
$obj = simplexml_load_string($result);
echo "<pre>";
print_r($obj);
echo "</pre>";
}catch (Exception $e) {
echo $e->getMessage();
}
Authorization enabled in linux server try to add correct username and password
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.