Today I ran into a problem according to wget and server error codes.
Actually I wanted to get the content-body inspite of the server status code.
Normally this should not happen, but in real situations we often get pages with status codes different from 200 and 302. For example if you have a php notice on the page, which is not visible, you can have 500 status code.
So, the problem is, that if wget gets back an error code, no matter what, it can’t ignore that.
It will no get the content body. We tried I guess everything, with no success.
So finally I ended up with a little php script, that uses file_get_contents, stream_context_create and ignore_errors in the http wrapper.
So here is my little code, which could save me a half day
$opts = array(
'ignore_errors' => true,
"User-Agent: Safari on Mac OS X Leopard: Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/523.12.2 (KHTML, like Gecko) Version/3.0.4 Safari/523.12.2\r\n".
$context = stream_context_create($opts);
$url = 'http://myurl';
$content = file_get_contents($url,null,$context);