wp_remote_get returns an error for valid URL

I currently have the following snippet of php to fetch some HTML and render it in my theme(squash theme).

<?php $response = wp_remote_get( 'http://www.toucan-it.co.uk/wp-content/themes/squash/index5.html' );

print $response ['body']; ?>

The file I’m trying to request is available at the following URL.

http://www.toucan-it.co.uk/wp-content/themes/squash/index5.html

Problem

The problem is when trying to retrieve ‘index5.html’ via the web browser the output of the file is generated but when calling it via ‘wp_remote_get’ using either absolute or relative paths an error is displayed.

Read More

When doing a var_dump of $response

The output can be seen on the homepage, beneath the sliders on the home page. You can see what should be rendered by the php file under the error code by looking at the Circles below (http://www.toucan-it.co.uk)

object(WP_Error)#337 (2) { ["errors"]=> array(1) { ["http_request_failed"]=> array(1) { [0]=> string(24) "couldn't connect to host" } } ["error_data"]=> array(0) { } } 

Related posts

1 comment

  1. Try to increase the timeout (default is 5).

    $response = wp_remote_get( 'http://www.toucan-it.co.uk/wp-content/themes/squash/index5.html', array( 'timeout' => 120, 'httpversion' => '1.1' ) );
    

Comments are closed.