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条)

报告相同问题?

悬赏问题

  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗
  • ¥500 把面具戴到人脸上,请大家贡献智慧,别用大模型回答,大模型的答案没啥用
  • ¥15 任意一个散点图自己下载其js脚本文件并做成独立的案例页面,不要作在线的,要离线状态。