【问题标题】:NTML Authentication with PHP to Navision SOAP webservice使用 PHP 到 Navision SOAP Web 服务的 NTLM 身份验证
【发布时间】:2021-05-01 10:43:42
【问题描述】:

我目前正在开发一个支付网关,该网关必须将订单发送到 Navision 进行管理。在 web 服务中启用了NTML 身份验证,因此首先需要扩展本机类SoapClient。为此,我在网络https://thomas.rabaix.net/articles/using-soap-php-with-ntlm-authentication 中找到了足够的文档,可以扩展这个原生类。

现在该帖子中公开的代码不会首先返回xslm

在这种情况下,这将是我的代码

            define("USERPWD", "user:password");

            require_once("NTLMStream.php");
            require_once("NTLMSoapClient.php");

            
            stream_wrapper_unregister('http');
            
            stream_wrapper_register('http', 'NTLMStream') or die("Failed to register protocol");
            
            // Initialize Soap Client  
            $url = "http://ipaddress:port/DynamicsNAV1_test/WS/enterprise/Codeunit/SalesEnterprise?WSDL";
            $uri = "urn:microsoft-dynamics-schemas/codeunit/SalesEnterprise";

            $params = [
                'stream_context' => stream_context_create([
                       'ssl' => [
                        'verify_peer'=>false, 
                        'verify_peer_name'=>false, 
                        'allow_self_signed'=>true,
                    ]]),
                'cache_wsdl'=> WSDL_CACHE_NONE,
                'trace' => 1,
            ];

            $client = new NTLMSoapClient($url, $params);
            
            stream_wrapper_restore('http');

如您所见,我已经省略了作者用来定义凭据的类。

最终代码返回如下错误:

SOAP Fault: (faultcode: WSDL, faultstring: SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://ipaddress:port/DynamicsNAV1_test/WS/Enterprise/Codeunit/SalesEnterprise?WSDL' : Document is empty).

如果需要,我很乐意提供更多信息。非常感谢!

【问题讨论】:

标签: php iis soap-client


【解决方案1】:

您从 NTLM 握手获得的前 2 个响应是没有正文的 401,如果成功通过身份验证,第三个响应将包含 200 和响应。

https://techcommunity.microsoft.com/t5/iis-support-blog/windows-authentication-http-request-flow-in-iis/ba-p/324645


21 年 1 月 30 日更新

自从我使用 Php 已经有一段时间了,但我从这篇文章开始,它展示了如何从 shell 手动执行 NTLM curl,然后如何从 php curl 重复相同的命令 - curl with ntlm authentication works in command line but not inside php

在这个 SO 搜索的前几个答案中也有一些掘金:https://stackoverflow.com/search?q=NTLM+PHP+curl

【讨论】:

  • 感谢您提供的信息,但我真的应该如何设置这些请求?我不排除在没有这个扩展的 SoapClient 类的情况下使用 curl,您有任何有用的信息或实际示例吗?
  • @naumb ive 扩展了我的答案,抱歉,我没有更具体的解决方案。希望这是您的起点。
  • 感谢您的帮助@MisterSmith。我会很快用解决方案更新帖子,
  • 你可以在这里看看我的回答stackoverflow.com/a/68823338/10030693
【解决方案2】:

我在相同的 SOAP 异常中遇到了这个问题,但与您的代码类似的代码在 NAV2013 中运行良好。我工作的公司升级到 NAV2020,然后出现 SOAP 异常。经过无数小时的重构和网络研究,解决方案在Microsoft documentation...问题是在 NTLMSoapClient 类的原始代码中,您必须更改以下行:

'Content-Type: text/xml; charset=UTF-8'

processRequest方法中的变量$headers下是:

'Content-Type: text/xml; charset=ISO-8859-1'

Dynamics API 有时不再接受带有 Unicode 字符的凭据。我希望这对你有用,就像对我一样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    • 1970-01-01
    相关资源
    最近更新 更多