【问题标题】:How to use curl with proxy and with japanese xml response如何将 curl 与代理和日语 xml 响应一起使用
【发布时间】:2013-10-16 05:53:54
【问题描述】:

我已经有一个可用的 curl,但我只能测试非代理网站。

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

$data = curl_exec($ch);
curl_close($ch);

但我需要它能够通过我的 api 中的代理(socks5)进行连接,我可以通过使用 firefox 并更改代理设置来测试它,api 返回一个带有日文字符的 xml。

【问题讨论】:

    标签: php curl proxy


    【解决方案1】:
    // connect using curl
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL,$url);
    
    // put the proxy settings here
    curl_setopt($ch, CURLOPT_PROXY,$proxyHost);         
    curl_setopt($ch, CURLOPT_PROXYPORT,$proxyPort);
    
    // connect with socks5
    curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_SOCKS5);
    
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    
    // get the response and close curl connection
    $data = curl_exec($ch);
    curl_close($ch);
    
    // Convert the return to xml object
    $sXML = $data;
    $oXML = new SimpleXMLElement($sXML);
    
    // show it in the browser, this is optional.
    echo '<pre>';       
    var_dump($oXML);
    echo </pre>;
    

    试试这个。请记住,$oXML 是一个 xml 对象,您可以使用 -> 运算符获取对象的子对象。

    【讨论】:

      猜你喜欢
      • 2014-03-06
      • 2012-11-06
      • 2015-07-22
      • 2016-10-31
      • 2010-12-11
      • 1970-01-01
      • 1970-01-01
      • 2012-03-13
      • 2019-01-30
      相关资源
      最近更新 更多