[英]I need to call an API which is working in windows but not in linux, I am getting 401 error
The following code is working on my Windows machine but the same code does not work on my server.以下代码在我的 Windows 机器上运行,但相同的代码在我的服务器上不起作用。 My server platform is Linux.我的服务器平台是Linux。
The error I get is:我得到的错误是:
Status Code: 401 Result: HTTP/1.1 401 Unauthorized状态代码:401 结果:HTTP/1.1 401 未经授权
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在linux服务器中启用授权尝试添加正确的用户名和密码
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.