简体   繁体   English

代理localhost上的cURL返回访问被拒绝

[英]cURL on proxied localhost returns Access Denied

I'm trying to access a .php file from another .php using cURL . 我正在尝试使用cURL从另一个.php访问.php文件。

Both are on localhost and I'm using a proxy . 两者都在localhost ,我正在使用proxy

THE PROBLEM 问题

If I try to access using postman or direct on the browser, the desired file returns correctly. 如果我尝试使用邮差或直接在浏览器上进行访问,则所需的文件将正确返回。

However, everytime that I try to access this file from another .php file using cURL , and passing all the proxy and auth values, it gives me the following: 但是,每次我尝试使用cURL从另一个.php文件访问此文件时,并传递所有proxy和auth值,它将为我提供以下内容:

Access Denied (authentication_failed) 拒绝访问(身份验证失败)

Your credentials could not be authenticated: "Credentials are missing.". 您的凭据无法通过身份验证:“凭据丢失。”。 You will not be permitted access until your credentials can be verified. 在可以验证您的凭据之前,您将无法访问。 This is typically caused by an incorrect username and/or password, but could also be caused by network problems. 这通常是由不正确的用户名和/或密码引起的,但也可能是由网络问题引起的。

For assistance, contact your network support team. 要获得帮助,请与您的网络支持团队联系。

Her is my cURL: 她是我的网址:

$curl = curl_init();

curl_setopt_array($curl,array(
    CURLOPT_PROXY => "proxy.myspecificproxy.com.br",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL => "localhost/MyDesiredFile.php?param=test&mail=test%40test.com",
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_PROXYUSERPWD => "myuser:mypassword123",
    CURLOPT_PROXYPORT => "8080",
    CURLOPT_PROXYTYPE => 'HTTP',
));


$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Any ideas? 有任何想法吗?

EDIT : 编辑

Beyond trying to access via postman or browser, if I cURL directly from the command line, it works too. 除了尝试通过邮递员或浏览器访问之外,如果我直接从命令行进行cURL访问,它也可以工作。

EDIT 编辑

Tried to disable the proxy for local addresses , but no change in the result. 尝试禁用本地地址的代理 ,但结果没有变化。

Is there a redirect involved? 是否涉及重定向? Remember that cURL doesn't follow redirects unless you tell it to, by passing the --location flag. 请记住,除非您通过传递--location标志将其告知重定向,否则cURL不会跟随重定向。

Does it work if you run it from the command line? 如果从命令行运行它是否可以工作? Try that, and try passing --verbose and --include to see the returned headers. 试试看,然后尝试传递--verbose--include来查看返回的标头。

Update your code as below 如下更新代码

$curl = curl_init();

curl_setopt_array($curl,array(
    CURLOPT_PROXY => "proxy.myspecificproxy.com.br",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL => "localhost/MyDesiredFile.php?param=test&mail=test%40test.com",
    CURLOPT_FOLLOWLOCATION => true,
    CURLOPT_PROXYUSERPWD => "myuser:mypassword123",
    CURLOPT_PROXYPORT => "8080",
    CURLOPT_PROXYTYPE => 'HTTP',
));


$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
<?php
$curl = curl_init();

curl_setopt_array($curl,array(
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_URL => "http://localhost/",
    CURLOPT_FOLLOWLOCATION => true,
));


$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}

Looks like it was a misconfiguration in the privileges. 看来这是特权的错误配置。

I contacted the support team of the company and the problem was solved. 我联系了公司的支持团队,问题得到解决。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM