连接到密码保护目录中的 SOAP API 时出现问题

发布于 2024-12-04 13:32:10 字数 1482 浏览 1 评论 0原文

我正在尝试使用 SOAP 访问 Magento API。我的代码正常工作,但是客户希望用密码保护 Magento 主文件夹。这样做会中断对 API 的访问并导致错误。

文档表明这不是问题,您只需指定用户名/密码即可,但这不起作用。

我使用 PHP 和 IIS,并通过 Plesk 10 设置密码保护。这是否使用基本 HTTP 身份验证或其他方式?

我的访问代码是:

$client = new SoapAuthClient($GLOBALS["magento_api_path"],array(  

                            'login'=>"admin", 
                            'password'=>"password" 
                          ) 
                    ); 
$session = $client->login($GLOBALS["magento_api_user"], $GLOABLS["magento_api_password"] ,
                    array(  

                            'login'=>"admin", 
                            'password'=>"password" 
                          ) ); 

我得到的错误是:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/' : failed to load external entity "http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/" in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php:20 Stack trace: #0 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->__call('login', Array) #1 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->login('backenduser', 'backendwebuser', Array) #2 {main} thrown in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php on line 20

引用的行是 $client->login 命令。

有什么建议吗?

I am trying to access a Magento API, using SOAP. the code I have works fine normally, however the client wishes to password protect the Magento main folder. Doing so breaks access to the API and causes an error.

The documentation suggests this isnt a problem and you can just specify the username/password, however this does not work.

I am using PHP and IIS, with the password protection set up via Plesk 10. Does this use Basic HTTP authentication or something else?

My access code is:

$client = new SoapAuthClient($GLOBALS["magento_api_path"],array(  

                            'login'=>"admin", 
                            'password'=>"password" 
                          ) 
                    ); 
$session = $client->login($GLOBALS["magento_api_user"], $GLOABLS["magento_api_password"] ,
                    array(  

                            'login'=>"admin", 
                            'password'=>"password" 
                          ) ); 

The error I get is:

Fatal error: Uncaught SoapFault exception: [WSDL] SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/' : failed to load external entity "http://www.domain.co.uk/magento/index.php/api/index/index/wsdl/1/" in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php:20 Stack trace: #0 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->__call('login', Array) #1 C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php(20): SoapClient->login('backenduser', 'backendwebuser', Array) #2 {main} thrown in C:\Inetpub\vhosts\domain.co.uk\httpdocs\backend\index.php on line 20

The line referred to is the $client->login command.

Any suggestions?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

撧情箌佬 2024-12-11 13:32:11

如果您查看 Mage_Api_Model_Server_Adapter_Soap::getWsdlUrl() 您会发现,magento 假定基本身份验证登录名和密码作为环境变量 PHP_AUTH_USERPHP_AUTH_PW 传递代码>.

If you look at Mage_Api_Model_Server_Adapter_Soap::getWsdlUrl() you will see, that magento assumes that basic auth login and password are passed as environment variables PHP_AUTH_USER and PHP_AUTH_PW.

朮生 2024-12-11 13:32:10

我很久以前就遇到过类似的问题。

就我而言,我没有立即意识到在创建 SoapClient 实例时需要使用 .htaccess 凭据,而是将 SOAP API 凭据传递给 login< /代码> 方法。

我在传递 SOAP API 凭据时遇到了与您类似的错误。

这对我有用(不过 1.3.x 版本。截至今天仍然对我有用):

$cProxy = new SoapClient(
    URL . 'index.php/api/soap/?wsdl',
    array(
        'login' => HTACCESS_USER,
        'password' => HTACCESS_PASS
    )
);
$rSessionId = $cProxy->login(
    SOAP_USER,
    SOAP_PASS
);

只是为了保存,你没有被打字错误所困:你传递 $GLOABLS["magento_api_password" ] 作为 login 方法的第二个参数,它应该是 $GLOBALS["magento_api_password"]

最后,您将第三个参数传递给 login 方法,我认为该方法已过时,因为据我所知,它被定义为仅具有两个参数:

<message name="login">
    <part name="username" type="xsd:string" />
    <part name="apiKey" type="xsd:string" />
</message>

I've faced a similiar problem long time ago.

In my case, I didn't immediately realize that I need to use .htaccess credentials while creating the SoapClient instance, but pass SOAP API credentials to the login method.

I was passing the SOAP API credentials all over and got a similiar error like you do.

Here's what worked for me (1.3.x version, though. Still works for me as of today):

$cProxy = new SoapClient(
    URL . 'index.php/api/soap/?wsdl',
    array(
        'login' => HTACCESS_USER,
        'password' => HTACCESS_PASS
    )
);
$rSessionId = $cProxy->login(
    SOAP_USER,
    SOAP_PASS
);

Just to play save, that you are didn't got trapped by a typo: you pass $GLOABLS["magento_api_password"] as 2nd param to the login method, which should be $GLOBALS["magento_api_password"].

Finally, you're passing a 3rd argument to the login method which I believe is obsolete, since afaik it's defined to have two params only:

<message name="login">
    <part name="username" type="xsd:string" />
    <part name="apiKey" type="xsd:string" />
</message>
初雪 2024-12-11 13:32:10

已经完成了:P

    $client = new SoapClient("http://${http_user}:${http_pass}@subdomain.domain.com", array(
        'login' => $user,
        'password' => $pass,
    ));

问题是,http 身份验证的使用仅在请求期间发生,而不是在第一个请求上实际获取 wsdl 时发生。要解决这个问题,只需使用我上面发布的格式: http://USERNAME:[电子邮件受保护]/

干杯

Been there, done that :P

    $client = new SoapClient("http://${http_user}:${http_pass}@subdomain.domain.com", array(
        'login' => $user,
        'password' => $pass,
    ));

The problem is that the use of the http auth only happens during the requests and not while actually fetching the wsdl on the first request. To get around that, simply use the format i posted above: http://USERNAME:[email protected]/

Cheers

白首有我共你 2024-12-11 13:32:10

这个问题可能是因为 Magento 在内部通过本地 HTTP 请求请求它自己的 WSDL。由于您已使用密码保护访问,因此它不会起作用。如果请求来自本地主机,请将安全性修改为不需要密码。

This problem is likely because internally Magento is requesting, via a local HTTP request, it's own WSDL. As you've password protected the access, it's not going to work. Modify the security to not require a password if the request is coming from localhost.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文