WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just did a clean install of Wordpress. But I have a problem when I install or use the WordPress API. So send me a sign

An Unexpected HTTP Error occurred during the API request.

The strange thing is that I have looked everywhere. And the solutions do not work for me porponen Wordpress 3.2.1 and do not know how to solve the problem

share|improve this question

Use the following function to debug the HTTP API request, you will get to know the actual reason why the HTTP API request is failing.

Paste the following code in your theme's function.php.

function dump_http_response( $response, $type, $transport, $args, $url ) {
    if ( is_admin() && $type == "response" )  {
        echo '<span style="color: #f00;">';
        var_dump( $response );
        echo '</span>';
add_action( 'http_api_debug', 'dump_http_response', 1, 5 );
share|improve this answer
With the above code shows me this message object(WP_Error)#3597 (2) { ["errors"]=> array(1) { ["http_request_failed"]=> array(1) { [0]=> string(83) "Failed trying to open by fopen() http://api.wordpress.org/plugins/info/1.0/" } } ["error_data"]=> array(0) { } } An Unexpected HTTP Error occurred during the API request. And do not get to do? – AlejoNext Sep 19 '11 at 18:27
it seems like you don't have permission to open urls using fopen. Try to use Core Control plugin which will allow you to choose the http transport to use. You will have more control on the http transport that will be used instead of fopen. – Hameedullah Khan Sep 20 '11 at 7:19
@HameedullahKhan http_api_debug has 5 arguments... – kaiser Jan 20 '13 at 11:30

This script gives you a rough overview what kind of filesystem mehods are allowed/installed on your server. The first three methods are the methods WordPress prefered and WordPress can be forced to use one of them by defining FS_METHOD in the wp-config.php.

Copy the code into a file, upload the file to your server, checkout which filesystem methods are allowed/installed and delete the file asap.

$yes = '<span style="color:green; font-weight:bold">:)</span>';
$no  = '<span style="color:red; font-weight:bold">:(</span>';
$items = array();

$items['fopen'][0] = 'Opening urls via fopen (for FS_METHOD "direct")';
$items['fopen'][1] = ( TRUE == ini_get( 'allow_url_fopen' ) ) ?
    ' is allowed '.$yes : ' is not allowed '.$no;

$items['ssh2'][0] = 'SSH2 (for FS_METHOD "ssh")';
$items['ssh2'][1] = ( TRUE === extension_loaded( 'ssh2' ) ) ?
    ' is installed '.$yes : ' is not installed '.$no;

$items['ftp'][0] = 'FTP (for FS_METHOD "ftpext")';
$items['ftp'][1] = ( TRUE === extension_loaded( 'ftp' ) ) ?
    ' is installed '.$yes : ' is not installed '.$no;

$items['sockets'][0] = 'Sockets (for FS_METHOD "ftpsockets")';
$items['sockets'][1] = ( TRUE === extension_loaded( 'sockets' ) ) ?
    ' are installed '.$yes : ' are not installed '.$no;

$items['curl'][0] = 'Curl';
$items['curl'][1] = ( TRUE === extension_loaded( 'curl' ) ) ?
    ' is installed '.$yes : ' is not installed '.$no;

echo '<html>';
echo '<ol>';

foreach ( $items as $item ) {
    printf( '<li>%s%s</li>', $item[0], $item[1] );

echo '</ol>';
echo '</html>';

You can try to force WordPress to use a filesystem method by defining it in your wp-config.php, e.g. to use the php ftp extension instead of fopen:

if ( ! defined( 'FS_METHOD' )
  define( 'FS_METHOD', 'ftpext' );

This could be helpfull if you got trouble using a filesystem method and want to use another one.

share|improve this answer

The "WordPress API" is a pretty vague (WP got multiple APIs). But from your error it seems that it's a HTTP API problem. There're multiple possible obstacles:

SSL Certificate issues

If you got a problem with your SSL certificate (necessary when the server is a subdomain of the site listed in the SSL certificate; using a wildcard certificate obviates the need for this).

As pointed out in the comments, the problem could also be that your server has out-of-date or missing SSL CA root certificates.

Request problems (WP HTTP API not responding 200/OK)

You think you ain't got cURL available and the fsocketopen fallback didn't work out?

First you want to check if the response works out. For this task, you can use two services (where both tell you slightly different details):

Then, as @HameedullahKhan pointed out in his answer, there's a debug filter for the WP HTTP API. This filter runs at the absolute last point of any request, right before giving it back to the developer.

/** Plugin Name: (#28871) Debug WP HTTP API response */
add_action( 'http_api_debug', 'wpse28871_debug_request', 999, 5 );
function wpse28871_debug_request( $response, $type, $class, $args, $url )
    printf( '<pre>ResponseData: %s', is_wp_error( $response ) 
        ? $response->get_error_code().' '.$response->get_error_message()
        : $response
    printf( '<br />ResponseType: %s',      $type );
    printf( '<br />ResponseClass: %s',     $class );
    printf( '<br />ResponseArgs: %s',      $args );
    printf( '<br />ResponseURl: %s</pre>', $url );
    # @TODO Uncomment to exit when debugging AJAX requests
    # exit();

If the above doesn't give you any insights, you can still try to debug the cURL object right after it got built and right before it got fired. This way is pretty unknown, but it has enormous powers when you combine it with above plugin: It tells you if the request has a problem with the cURL args or if it fails later, narrowing down the range of possible problems pretty fast.

/* Plugin Name: (#28871) Debug WP HTTP API cURL arguments */
add_action( 'http_api_curl', 'wpse28871_curl_debug' );
function wpse28871_curl_debug( $handle )
        ,var_export( curl_getinfo( $handle, CURLINFO_HEADER_OUT ), true ) )
share|improve this answer
+1, but note that if the problem is with the requesting site not recognising the target's SSL certificate as valid, then it's probably just a server configuration issue. – webaware Jan 19 '13 at 23:14
@webaware +1 to your comment - added to the answer (which you can do yourself the next time with using the "edit" button). Sidenote: Fixing the certificate was what I tried first (for a very long time) and that didn't do it (on a Linux server), so I came up with this. And as this plugin only triggers during update, it's pretty save. – kaiser Jan 20 '13 at 11:34
your problem was different, the certificate was domain-specific and not a wildcard certificate so it was not valid for subdomains. As for editing other's answers, I've done that a few times with novices but shy away from doing that with "experts" since I pissed off chirp bennett by correcting him :) – webaware Jan 20 '13 at 22:54
@webaware Well, I'm not Chip ;) And yes, it's absolutely ok having edits on my answers. (That's how the system works). And mostly when it's additions - you can see that from my edit reflecting your comment. If I don't agree I can still revert it. Cheers. – kaiser Jan 21 '13 at 1:32

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.