Need simplexml_load_file through a proxy

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
CSTechie
Forum Newbie
Posts: 4
Joined: Tue Apr 04, 2006 3:04 pm

Need simplexml_load_file through a proxy

Post by CSTechie »

I'm hoping that someone has experience using PHP 5's simplexml_load_file while connecting through a proxy.

I can't seem to get the right combination to make this all fly and maybe I can't actually use simplexml with a proxy. I've spent a fair bit of time getting nowhere fast so any and all help would be so very appreciated.

It works great if I just have a basic url to the rss feed, but as soon as I introduce a myriad of ways to use the proxy, the whole thing tanks and I haven't seen any examples of this combination out there, but I'm sure that many people have done this, right?

Help. Please. Thank you!!!

CS
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

have you tried making requests through the proxy that aren't related to the simplexml extension?
CSTechie
Forum Newbie
Posts: 4
Joined: Tue Apr 04, 2006 3:04 pm

Post by CSTechie »

The short answer is yes.

I've used this and gotten back data in $index and switched to use simplexml_load_string vs simplexml_load_file

$options = array(
'http' => array(
'header' => "Proxy: http://www.proxyserver.com:80\r\n"
)
);

$context = stream_context_create($options);
$index = file_get_contents("$this->url_get",
false, $context);


But I've been very unsuccessful at getting the data to be read as xml data. I get different errors when I try different combinations, but I do know that the proxy works.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what about using simplexml_load_string()
CSTechie
Forum Newbie
Posts: 4
Joined: Tue Apr 04, 2006 3:04 pm

Post by CSTechie »

I should have put this up from the start. This is what I have when I use simplexml_load_string()

$options = array(
'http' => array(
'header' => "Proxy: http://www.proxyserver.com:80\r\n"
)
);

$context = stream_context_create($options);
$index = file_get_contents("$this->url_get",
false, $context);

line 88: $xml_object = simplexml_load_string($index);



Output:

Warning: Entity: line 1: parser error : Start tag expected, '<' not found in file.php on line 88

Warning: $index in file.php on line 88

Warning: ^ in file.php on line 88
Post Reply