[英]Why am I Getting "401 Unauthorized" for Microsoft Graph API Call?
[英]I need to call an API which is working in windows but not in linux, I am getting 401 error
以下代碼在我的 Windows 機器上運行,但相同的代碼在我的服務器上不起作用。 我的服務器平台是Linux。
我得到的錯誤是:
狀態代碼:401 結果:HTTP/1.1 401 未經授權
我的代碼:
<?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();
}
在linux服務器中啟用授權嘗試添加正確的用戶名和密碼
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.