Inconsistent server code response using HTTP API

Disclaimer: I can’t give you a real explanation why this happens. I investigated this issue multiple times and (like you) didn’t even get a consistent error behavior. Anyway: Every sort of RESTful remote request using a remote API is painful and error prone – it simply highly depends what the counter part gives you… not.

But… sometimes the problem is the SSL certificate and secure connections simply doesn’t work out.

Disable SSL verification

The (plain stupid) solution to this is to turn it off with the second argument inside the remote request API function:

wp_remote_get( $api_url, array( 'sslverify' => false ) );