WordPress: Fixing Error during API request
Using WordPress 3 and above, some web hosting service would return "An Unexpected HTTP Error occurred during the API request". Most of the solutions provided by wordpress users are, modifying php code in the class-http.php under wp-includes/ (and it is http.php with wordpress 2)
The code involved would be (and there is only 1 line with such code in class-http.php:
'timeout' => apply_filters( 'http_request_timeout', 5),
change to
'timeout' => apply_filters( 'http_request_timeout', 30),
and thus allowing webserver to fetch external site data with longer time.
However in my case, I still have to use Core Control in order to get rid of the problem. I have written similar post regarding Core Control in the past, to upgrade my wordpress; and you may read it if interested.
Search plugin for "Core Control", install and activate it. Go to Core Control configuration under Tools > Core Control.
Next, check HTTP Access Module 1.0, and click save modules choices, as depicted on screenshot below.
After save changes, you will see External HTTP Access link on the menu bar, beside the Main Page. Go to the new link, and you will see the screenshot below:
For normal server, as you click on Test Transport, you would get the success message as below:
Successfully retrieved & verified document from http://tools.dd32.id.au/wordpress/core-control.php
For my current web hosting, whenever I click on Test Transport for cURL, I get the error message:
An Error has occured: name lookup timed out
In this case, you have to disable cURL Transport by clicking Disable Transport.
And this would probably solve your "An Unexpected HTTP Error occurred during the API request" error message in wordpress.
Liberty Reserve – XML API with SSL error fix
Back to few days ago, Liberty Reserve (LR) XML API is not working in my PHP script, when I try to retrieve the transaction history. If you do not know what is LR, it is one of the largest E-currency payment gateway.
I have been using CURL to retrieve the information for since few months ago. By using curl_error function, PHP output the following error:
SSL read: error:00000000:lib(0):func(0):reason(0), errno 104
It seem like is the SSL is causing the problem. Ignoring the CURL, I use file_get_contents to fetch the URL information without luck. However, the information can be retrieved if I paste the long XML encoded URL directly into the browser. By doing some research on Google on SSL with CURL, finally I fixed the problem with my own.
The solution is just to add another line of code curl_setopt if you have not done so:
// $ch - initialized CURL resource curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 5.01; Windows NT 5.0)"
Normally user agent is set if the site allow legit browser only. Not sure why LR is changing this all of sudden, but at least the fix is working for me.
WordPress Plugin API error during installation
When I was logged into WP (2.8.5) and I tried to install a new plugin (from the dashboard), I would get the following error:
“An Unexpected HTTP Error occured during the API request.”
Basically, according to WP user efree_unix,
The cause of error is too long in the process of requesting the API plugin in the wordpress server so that the operation timed out. By default, wordpress give 5 seconds time limit to request a plugin. If within 5 seconds does not get a replay, then the process will be stopped and displayed an error “An Unexpected HTTP error occurred during the API request.”
THE SOLUTION:
Open wp_include/http.php file on line 223
‘timeout’ => apply_filters( ‘http_request_timeout’, 5),
change the script above into
‘timeout’ => apply_filters( ‘http_request_timeout’, 30),
You may refer to efree_unix's post at here. At least it works for me


Like