【问题标题】:PHP curl on Linux: what is the difference to curl on windows?Linux 上的 PHP curl:在 Windows 上 curl 有什么区别?
【发布时间】:2012-03-22 12:09:04
【问题描述】:

我正在尝试从 Ubuntu Server 11.10 运行我的 php 应用程序。这个应用程序在 Windows 中的 Apache + PHP 下运行良好。我还有其他应用程序,我可以简单地在 2 个操作系统之间复制和粘贴,它们都可以在这两个操作系统上运行。

然而,这个使用 php 库 tonic (RESTful webservices) 并使我们使用 php cURL 模块。问题是我没有收到导致无法找到问题的错误消息。

我(必须)使用 NTLM 身份验证,这是通过 AuthenNTLM Apache 模块完成的:

Order allow,deny
Allow from all

PerlAuthenHandler Apache2::AuthenNTLM

AuthType ntlm

AuthName "Protected Access"

require valid-user

PerlAddVar ntdomain "domainName server"

PerlSetVar defaultdomain domainName

PerlSetVar ntlmsemtimeout 2

PerlSetVar ntlmdebug 1

PerlSetVar splitdomainprefix 0

cURL 需要获取的所有文件都会覆盖 AuthenNTLM 身份验证:

order deny,allow
deny from all
allow from 127.0.0.1
Satisfy any

由于这些文件仅受来自同一服务器的 cURL 感染,因此可以将访问限制为 localhost。

可能的问题是:

  • 对于通过 cURL 请求的文件,不会覆盖 NTLM 身份验证(即使设置了 AllowOverride All)

  • curl 在 linux 上的工作方式不同

    $ch = curl_init();
    curl_setopt($ch, CURLOPT_COOKIE, $strCookie);
    curl_setopt($ch, CURLOPT_URL, $baseUrl . $queryString);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    $html = curl_exec($ch);
    curl_close($ch);
    
  • 其他?

Apache 日志说:

[错误] /myApp/webservice/local/viewList.php 的错误/缺少 NTLM/基本授权标头

但是这个目录应该覆盖 NTLM 身份验证

编辑:

使用来自 windows 的 curl 命令行来访问我得到的相同资源:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html>
    <head>
        <title>406 Not Acceptable</title>
    </head>
    <body>
        <h1>Not Acceptable</h1>
        <p>An appropriate representation of the requested resource /myApp/webservice/myResource could not be found on this server.</p>
        Available variants:
        <ul>
        <li><a href="myResource.php">myResource.php</a> , type application/x-httpd-php</li>
        </ul>
        <hr>
        <address>Apache/2.2.20 (Ubuntu) Server at localhost Port 80</address>
    </body>
</html>

【问题讨论】:

标签: php libcurl ntlm


【解决方案1】:

问题是 Ubuntu 上的默认 Apache 配置:

Options Indexes FollowSymLinks MultiViews

MultiViews 正在将 request_uri 从 myResource 更改为 myResource.php。

解决方案:

  • 在 .htaccess 中禁用多视图:选项 -MultiViews
  • 从默认配置中移除 MultiViews
  • 将文件作为示例重命名为 myResourceClass

我选择了最后一个选项,因为无论配置如何,它都应该可以工作,而且我只有 3 个这样的文件,所以更改大约需要 30 秒...

【讨论】:

    猜你喜欢
    • 2017-03-04
    • 1970-01-01
    • 2015-12-06
    • 1970-01-01
    • 2011-04-06
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 2013-02-19
    相关资源
    最近更新 更多