note 91384 added to domdocument.load

From: Date: Tue, 09 Jun 2009 15:18:58 +0000
Subject: note 91384 added to domdocument.load
Groups: php.notes 
Request: Send a blank email to php-notes+get-156613@lists.php.net to get a copy of this message
I had a problem with loading documents over HTTP. I would get errors looking like this: Warning: DOMDocument::load(http://external/document.xml): failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error The document would load fine in browsers and using wget. The problem is that DOMDocument::load() on my systems (both OS X and Linux) didn't send any User-Agent header which for some weird reason made Microsoft-IIS/6.0 respond with the 500 error. The solution is found on http://php.net/manual/en/function.libxml-set-streams-context.php : <?php $opts = array( 'http' => array( 'user_agent' => 'PHP libxml agent', ) ); $context = stream_context_create($opts); libxml_set_streams_context($context); // request a file through HTTP $doc = DOMDocument::load('http://www.example.com/file.xml'); ?> ---- Server IP: 195.184.96.15 Probable Submitter: 83.94.133.86 ---- Manual Page -- http://www.php.net/manual/en/domdocument.load.php Edit -- https://master.php.net/note/edit/91384 Del: integrated -- https://master.php.net/note/delete/91384/integrated Del: useless -- https://master.php.net/note/delete/91384/useless Del: bad code -- https://master.php.net/note/delete/91384/bad+code Del: spam -- https://master.php.net/note/delete/91384/spam Del: non-english -- https://master.php.net/note/delete/91384/non-english Del: in docs -- https://master.php.net/note/delete/91384/in+docs Del: other reasons-- https://master.php.net/note/delete/91384 Reject -- https://master.php.net/note/reject/91384 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#156613) next »