post 使用 cURL 从服务器使用 proxy/firewall 到远程服务器
post to a remote server using cURL from a server using proxy/firewall
我正在开发一个 wordpress 插件,它 post 使用 cURL 将数据发送到远程服务器。
这在大多数网站上都可以正常工作,但在某些网站上它只会出现错误访问被拒绝。
[headers] => Array
(
[server] => squid/3.3.8
[mime-version] => 1.0
[date] => Tue, 31 Mar 2015 07:32:51 GMT
[content-type] => text/html
[content-length] => 3406
[x-squid-error] => ERR_ACCESS_DENIED 0
[vary] => Accept-Language
[content-language] => en
[x-cache] => MISS from hproxy2.world4you.com
[x-cache-lookup] => NONE from hproxy2.world4you.com:3128
[via] => 1.1 hproxy2.world4you.com (squid/3.3.8)
[connection] => close
)
以上是我收到的回复。
下面是我正在使用的代码
function testpost($ac,$d_name,$an,$data) {
$fields = '';
foreach ($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_RETURNTRANSFER,true);
curl_setopt($post, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($post, CURLOPT_URL, $ac);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($post, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($post);
echo "<pre>";
print_r($result);
echo "</pre>";
}
此外,在某些服务器上它一直在执行,而不是 return 任何东西。对于那些无法弄清楚问题所在甚至无法向用户显示一些错误消息的人,因为它没有 return 任何东西。
例如
如果我在 abc.com 上安装插件并尝试 POST 使用 cURL 到 xyz.com/test.php,在 test.php 中我已经编写了写入数据的代码到文本文件中以检查来自 abc.com 的 cURL 请求是否到达 xyz.com。但它不会将任何内容写入文本文件,这意味着请求未从 abc.com 到达 xyz.com。在此我没有得到任何响应并且它在 abc.com 上执行了很长时间。
因此,我需要帮助找出造成此问题的原因以及如何将 POST 数据从 abc.com 更改为 xyz.com
squid(代理)正在阻止您的请求。去看看 squid 的日志为什么它阻止了请求。
您所在的网站或服务器 运行 您的插件位于防火墙后面,因此它阻止了您的 cURL 请求。为了克服这个插件的这个用户必须通过他们的服务器代理设置。
见下文-
function testpost($ac,$d_name,$an,$data,$proxy_ip,$proxy_port,$login_passw) {
$fields = '';
foreach ($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_RETURNTRANSFER,true);
curl_setopt($post, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($post, CURLOPT_URL, $ac);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($post, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($post, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($post, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($post, CURLOPT_PROXY, $proxy_ip);
curl_setopt($post, CURLOPT_PROXYUSERPWD, $login_passw);
$result = curl_exec($post);
echo "<pre>";
print_r($result);
echo "</pre>";
}
我正在开发一个 wordpress 插件,它 post 使用 cURL 将数据发送到远程服务器。 这在大多数网站上都可以正常工作,但在某些网站上它只会出现错误访问被拒绝。
[headers] => Array
(
[server] => squid/3.3.8
[mime-version] => 1.0
[date] => Tue, 31 Mar 2015 07:32:51 GMT
[content-type] => text/html
[content-length] => 3406
[x-squid-error] => ERR_ACCESS_DENIED 0
[vary] => Accept-Language
[content-language] => en
[x-cache] => MISS from hproxy2.world4you.com
[x-cache-lookup] => NONE from hproxy2.world4you.com:3128
[via] => 1.1 hproxy2.world4you.com (squid/3.3.8)
[connection] => close
)
以上是我收到的回复。
下面是我正在使用的代码
function testpost($ac,$d_name,$an,$data) {
$fields = '';
foreach ($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_RETURNTRANSFER,true);
curl_setopt($post, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($post, CURLOPT_URL, $ac);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($post, CURLOPT_SSL_VERIFYHOST, 2);
$result = curl_exec($post);
echo "<pre>";
print_r($result);
echo "</pre>";
}
此外,在某些服务器上它一直在执行,而不是 return 任何东西。对于那些无法弄清楚问题所在甚至无法向用户显示一些错误消息的人,因为它没有 return 任何东西。
例如 如果我在 abc.com 上安装插件并尝试 POST 使用 cURL 到 xyz.com/test.php,在 test.php 中我已经编写了写入数据的代码到文本文件中以检查来自 abc.com 的 cURL 请求是否到达 xyz.com。但它不会将任何内容写入文本文件,这意味着请求未从 abc.com 到达 xyz.com。在此我没有得到任何响应并且它在 abc.com 上执行了很长时间。
因此,我需要帮助找出造成此问题的原因以及如何将 POST 数据从 abc.com 更改为 xyz.com
squid(代理)正在阻止您的请求。去看看 squid 的日志为什么它阻止了请求。
您所在的网站或服务器 运行 您的插件位于防火墙后面,因此它阻止了您的 cURL 请求。为了克服这个插件的这个用户必须通过他们的服务器代理设置。 见下文-
function testpost($ac,$d_name,$an,$data,$proxy_ip,$proxy_port,$login_passw) {
$fields = '';
foreach ($data as $key => $value) {
$fields .= $key . '=' . $value . '&';
}
rtrim($fields, '&');
$post = curl_init();
curl_setopt($post, CURLOPT_RETURNTRANSFER,true);
curl_setopt($post, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt($post, CURLOPT_URL, $ac);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($post, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($post, CURLOPT_PROXYPORT, $proxy_port);
curl_setopt($post, CURLOPT_PROXYTYPE, 'HTTP');
curl_setopt($post, CURLOPT_PROXY, $proxy_ip);
curl_setopt($post, CURLOPT_PROXYUSERPWD, $login_passw);
$result = curl_exec($post);
echo "<pre>";
print_r($result);
echo "</pre>";
}