简体   繁体   English

我需要调用一个可以在 windows 中运行但在 linux 中不能运行的 API,我收到 401 错误

[英]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 passwordlinux服务器中启用授权尝试添加正确的用户名和密码

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERPWD, "myusername:mypassword");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么我在 Microsoft Graph API 调用中收到“401 Unauthorized”? - Why am I Getting "401 Unauthorized" for Microsoft Graph API Call? 如何使用php curl正确调用API? 我收到401的http状态码 - How do i call an API using php curl correctly? I am getting http status code of 401 Google PHP Api客户端-我不断收到错误401:未经授权 - Google PHP Api Client - I keep getting Error 401: UNAUTHENTICATED 我使用哪个IP地址调用外部API? - Which IP address am I using to call an external API? 这是我作为 API 响应得到的什么类型的结果? - What type of result is this which i am getting as API response? 为什么我从 api 和 api 资源管理器收到 500 错误 - Why am I getting a 500 error from api and api explorer 为什么我在控制器中的模型调用期间出现禁止错误 - Why I am getting forbidden error during model call in controller 在使用Codeigniter进行Soap调用期间出现控制台错误 - I am getting console error during soap call using codeigniter 为什么我会收到“调用未定义的方法 User::emailExists()”错误? - Why am I getting a `Call to undefined method User::emailExists()` error? PHP-为什么会出现此错误? 调用未定义的函数 - PHP - Why am I getting this error? Call to undefined function
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM