从代理服务器cURL内容


cURL contents from Proxy Server?

我想通过代理获取内容,我尝试了以下代码,但我没有得到代理的内容!我得到重定向的值,但之后我不能回它的内容!谁能告诉我怎么修理它?提前谢谢。

<?php
//create array of data to be posted
$post_data['u'] = 'http://api.somesite.com/get?apikey=w3ijwiefjdigashdufhsaiufs34r4';
$post_data['encodeURL'] = 'on';
$post_data['allowCookies'] = 'on';
$post_data['stripJS'] = 'on';
$post_data['stripObjects'] = 'on';
//u'
//traverse array and prepare data for posting (key1=value1)
foreach ( $post_data as $key => $value) {
    $post_items[] = $key . '=' . $value;
}
//create the final string to be posted using implode()
$post_string = implode ('&', $post_items);
//create cURL connection
$curl_connection =
  curl_init('http://zend2.com/includes/process.php?action=update');
//set options
curl_setopt($curl_connection, CURLOPT_CONNECTTIMEOUT, 30);

curl_setopt($curl_connection, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl_connection, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl_connection, CURLOPT_FOLLOWLOCATION, 1);
//i added these two lines
curl_setopt($curl,CURLOPT_FOLLOWLOCATION,TRUE);
curl_setopt($curl,CURLOPT_MAXREDIRS,2);//only 2 redirects
//set data to be posted
curl_setopt($curl_connection, CURLOPT_POSTFIELDS, $post_string);
//perform our request
$result = curl_exec($curl_connection);

//show information regarding the request
print_r(curl_getinfo($curl_connection));
echo curl_errno($curl_connection) . '-' .
                curl_error($curl_connection);
$info = curl_getinfo($curl_connection); 
$url2 = $info['redirect_url'];
echo "redirect_url:".$url2;
echo result;

您需要设置CURLOPT_PROXY以通过代理。以上值参考curl文档