php curl 获取代理 [英] php curl get proxy

查看:44
本文介绍了php curl 获取代理的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 Windows 中使用 PHP 脚本来发出 curl 请求以成功发出 SOAP 请求,并且我正在尝试准确地追踪这个成功的请求是如何在 C#.NET 中复制它的.

I am using a PHP script in Windows to make a curl request to successfully make a SOAP request, and I'm trying to track down exactly how this successful request is made to replicate it in C#.NET.

如何使用 PHP 来检测 curl 将使用哪个代理服务器?

How can I use PHP to detect which proxy server curl is going to use?

我希望 php curl 中可能有一个 curl_getopt,所以我可以这样做:

I was hoping there might be a curl_getopt in php curl, so I could do something like:

curl_getopt(CURLOPT_PROXY);

可惜它不存在.

有什么办法可以让我找出php curl 将通过哪个代理服务器进行连接?

Is there any way for me to find out which proxy server php curl will be connecting through?

推荐答案

1.你告诉 curl 使用什么代理,而不是 viaversa:

function wget($url)
{
    $options = array(
        CURLOPT_URL             => $url,
        CURLOPT_HEADER          => false,
        CURLOPT_FOLLOWLOCATION  => true,
        CURLOPT_RETURNTRANSFER  => true,
        CURLOPT_TIMEOUT         => 30,
        CURLOPT_PROXY           => '...proxy.ip...',
        CURLOPT_PROXYPORT       => '...proxy.port...',
        CURLOPT_USERAGENT       => 'Mozilla/5.0 (Windows; U; Windows NT 5.1; ru; rv:1.8.0.9) Gecko/20061206 Firefox/1.5.0.9',
    );
    $ch = curl_init();
    curl_setopt_array($ch, $options);
    $content = curl_exec($ch);
    $error = curl_error($ch);
    return (!$error && $content) ? $content : null;
}

2.另一种解决方案>

看看这个答案> 如何获得之前使用 curl_setopt() 设置的选项?

http://php.net/manual/en/function.override-function.php

附言您可能需要 http://php.net/manual/en/function.重命名函数.php

http://php.net/manual/en/book.runkit.php

这篇关于php curl 获取代理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆