我想通过代理获取内容我尝试了以下代码,但我没有得到代理的内容!我得到重定向的价值但在那之后我不能回应它的内容!谁能告诉我如何解决它?提前谢谢。
<?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;