【问题标题】:403 Error - Forbidden error on making curl request403 错误 - 发出 curl 请求时出现禁止错误
【发布时间】:2012-10-02 16:58:33
【问题描述】:

我有两个虚拟主机,xyz.com 和 abc.com。从 xyz.com 我正在向http://abc.com/test 进行 curl 后调用(使用 PHP) 这将返回“403 错误 - 禁止”(http://abc.com/test 在浏览器中运行良好)

我知道这个问题听起来很重复。对此感到抱歉,因为我已经完成了之前答案中给出的所有解决方案,但没有任何效果:-(

  1. 我在 Apache 中的根文件夹(doc root)有 775 个权限。
  2. 在 httpd.conf 我的控件如下

    Options FollowSymLinks
    AllowOverride All
    Order allow,deny
    Allow from all
    
  3. 我还尝试在代码中添加 USERAGENT(firefox 的)来模拟浏览器。

我没有得到 Apache 的确切问题。我正在使用 Apache 2.4

有人可以帮忙解决这个问题吗?

更新 下面是我用来发送请求的代码。

$curl = curl_init();
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)');
curl_setopt($curl, CURLOPT_TIMEOUT, 20);
curl_setopt($curl, CURLOPT_URL, 'http://abc.com/test');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, 'a=b&c=d&e=f');
$headers[] = 'Content-Type:application/x-www-form-urlencoded';
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($curl);

【问题讨论】:

  • 也添加您的代码以更快地获得答案。
  • 哪个代码? abc.com/test 或我用来发送 curl 请求的代码? (我猜,Apache 似乎有问题)
  • 会不会是标题之一?
  • 可能是.. 我无法弄清楚究竟是哪个代码。也许,我已经用发送 curl 调用的代码更新了问题。
  • 你不需要添加 content-type 标题,curl 会在 curlopt_post 为 true 的情况下自动添加。

标签: php apache curl http-status-code-403


【解决方案1】:

啊,解决了。刚刚改变:

Options FollowSymLinks

到:

Options +FollowSymLinks

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-10
    • 2019-08-07
    • 2013-10-20
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    • 2016-01-12
    • 2013-07-19
    相关资源
    最近更新 更多