dsakktdog498483070 2012-09-27 09:50
浏览 75
已采纳

php curl获取代理

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.

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

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

curl_getopt(CURLOPT_PROXY);

but alas it doesn't exist.

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

  • 写回答

3条回答 默认 最新

  • doolo00026 2012-09-27 09:53
    关注

    1. You tell curl what proxy to use, and not 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. Another solution >

    And look at this answer > How to get an option previously set with curl_setopt()?

    3. Override curl_setopt() function

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

    p.s. you should probably need http://php.net/manual/en/function.rename-function.php

    4. Use runkit to override functions

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路