내가 사용하는 프록시와 함께 PHP에서 다음 코드를 실행하려고 :프록시 서버가있는 simplexml_load_file()? 방법?
$data = simplexml_load_file('http://www.testdomain.com/data/search?q='.
urlencode($searchstring).'&format=xml');
URL이 프록시 서버를 통해 가져올 수 있도록 어떻게 내가이 코드를 수정할 수 있습니다? 몇 가지 예제를 발견했지만 모두 cURL을 사용하고 있으며 구현 방법을 정확히 알지 못합니다.
도움이 될 것입니다.
주석 : 이렇게 작동합니까?
$url = "http://www.testdomain.com/data/search?q='.urlencode($searchstring).'&format=xml";
$agent = "Mozilla/5.0 (X11; U; Linux i686; en-US)
AppleWebKit/532.4 (KHTML, like Gecko)
Chrome/4.0.233.0 Safari/532.4";
$referer = "http://www.google.com/";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
curl_setopt($ch, CURLOPT_PROXY, '202.95.141.129:8080');
curl_setopt($ch, CURLOPT_REFERER, $referer);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_MAXREDIRS, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_USERAGENT, $agent);
$curldata = curl_exec($ch);
curl_close($ch);
$data = simplexml_load_string($curldata);
?
http://php.net/simplexml_load_file - 프록시 서버를 지정할 수있는 스트림 컨텍스트가 있습니다. http://php.net/libxml_set_streams_context - HTTP에 대한 프록시 및 기타 스트림 컨텍스트 옵션 : http : //php.net/context.http – hakre