I’m making a plugin that calls my own REST API. Previously I used curl without any problems, but to get the plugin approved I need to use wp_remote_get() instead.
When I use wp_remote_get(), I can call my REST API function, but the function doesn’t receive the request arguments.
1) My curl looked like this:
$url = "https://www.modeltrainprices.com/wp-json/public/get-product?brand=" . $atts['brand'] . "&model=" . $atts['model'] .
"¤cy=" . $atts['currency'] . "&key=" . $atts['api-key'];
$curl_handle = curl_init($url);
curl_setopt($curl_handle, CURLOPT_HTTPGET, true);
curl_setopt($curl_handle, CURLOPT_RETURNTRANSFER, true);
$response_json = curl_exec($curl_handle);
curl_close($curl_handle);
$response = json_decode($response_json, true);
No problems. REST API function called and the function receive the arguments from the url.
2) This is my wp_remote_get() implementation:
$url = "https://www.modeltrainprices.com/wp-json/public/get-product";
$args = array(
"brand" => $atts['brand'],
"model" => $atts['model'],
"currency" => $atts['currency'],
"key" => $atts['api-key']
);
$response = wp_remote_get($url, $args);
$response_json = wp_remote_retrieve_body($response);
$response_data = json_decode($response_json, true);
Function is getting called, but the request arguments aren’t received.
3) I try to get the request arguments like this in my REST API function:
$brand = esc_sql($request['brand']);
$model = esc_sql($request['model']);
$currency = esc_sql($request['currency']);
$api_key = esc_sql($request['key']);
Anyone who can spot what is going wrong? Why does my curl implementation work, while my wp_remote_get() doesn’t work?
Thanks,
Mads
when used wp_remote_get getting following error – WP_Error Object ( [errors] => Array ( [http_request_failed] => Array ( [0] => cURL error 7: ) )
When using CURL, curl info is coming as follows without any errors :- Array ( [url] => feedurl?token [content_type] => [http_code] => 0 [header_size] => 0 [request_size] => 0 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 0.002587 [namelookup_time] => 0.002671 [connect_time] => 0 [pretransfer_time] => 0 [size_upload] => 0 [size_download] => 0 [speed_download] => 0 [speed_upload] => 0 [download_content_length] => -1 [upload_content_length] => -1 [starttransfer_time] => 0 [redirect_time] => 0 [redirect_url] => [primary_ip] => [certinfo] => Array ( ) [primary_port] => 0 [local_ip] => [local_port] => 0 )
Can someone please help me to fix these issues and make it working.
]]>I am working with two sites on separate servers/hosts and I am trying to connect to the REST api of one from the other. I use wp_remote_get() on SITE A to connect to the /wp-json/ endpoint of SITE B but I receive the following error:
cURL error 60: SSL certificate problem: self signed certificate
I have connected to SITE B on all other websites in the same way without any issues. I can connect to other websites on SITE A without any issues (for example, I can connect to https://www.ads-software.com/wp-json/ on SITE A).
SITE A is on managed hosting so I don’t have direct access to the configuration files so I rely on them for making these changes. They seem unwilling to help troubleshoot this issue and put the onus on me. I can make SITE B server changes to this site if necessary.
I have read that this could be an issue with the certificate list that the cURL function uses. So I downloaded the latest CA PEM file (cacert.pem) and had my host point curl.cainfo option to this file in PHP.ini (curl.cainfo=”/dirto/cacert.pem”). This did not fix the issue.
I tried to use wp_remote_get(‘SITE B’, [‘sslverify’ => false]) to test without SSL. This seems to reach SITE B but it returns an 403 unauthorized error or 500 critical error.
I also tried to get the public key of SITE B by using openssl command in terminal and add that key to cacert.pem but that didn’t seem to fix it.
If this can help diagnose, when I do openssl to the certificate on SITE B I get:
depth=1 O = Digital Signature Trust Co., CN = DST Root CA X3
verify error:num=10:certificate has expired
notAfter=Sep 30 14:01:15 2021 GMT
verify return:0
depth=1 O = Digital Signature Trust Co., CN = DST Root CA X3
verify error:num=10:certificate has expired
notAfter=Sep 30 14:01:15 2021 GMT
verify return:0
depth=3 O = Digital Signature Trust Co., CN = DST Root CA X3
verify error:num=10:certificate has expired
notAfter=Sep 30 14:01:15 2021 GMT
verify return:0
-----BEGIN PUBLIC KEY-----
[KEY]
-----END PUBLIC KEY-----
NOTE: It says “certificate has expired” but it’s not expired when I visit it in a browser or from any SSL checker tool. I think this is something to do with LETS ENCRYPT having a cross-sign expired (https://letsencrypt.org/docs/dst-root-ca-x3-expiration-september-2021/). This cert is in SITE A’s cacert.pem file.
I have cURL version 7.61.1 OpenSSL/1.1.1k
Any help would be appreciated.
]]>The new version is not sending automatically and when I click process queue it always gives a cURL error as follows.
SMTP Mailing Queue : Unable to call process queue due to following error ‘cURL error 28: Operation timed out after 5001 milliseconds with 0 bytes received’
I have downgraded to version 1.4.0 which was working ok before but I notice that in the repository the latest version says Development Mode.
If it is in development mode why was it made available to upgrade without stating that and please advise when it will be available properly for use on production site.
Thanks.
]]>I need to run this once a minute for all FTP processing and other maintenance actions:
curl -silent -A ‘Mozilla’ ‘https://www.mysite.com/?c=1&ss_c=33xxxxxxxxxxxxxxxx2′ >/dev/null 2>&1
Now I’m manually running it and it works
I don’t have Cpanel then I added a PHP cron event in WP Crontrol plugin
wp_remote_get(get_site_url().”/?c=1&ss_c=33xxxxxxxxxxxxxxxx2″);
it’s configured properly and running every minute, but I’m not getting FTP processing and other maintenance actions as in manual
Any suggestion?
]]>I need to run this once a minute for all FTP (photos) processing and other maintenance actions:
curl -silent -A ‘Mozilla’ ‘https://www.mysite.com/?c=1&ss_c=3326p5781w2f2drgq8j2’ >/dev/null 2>&1
Now I’m manually running it
I added a PHP cron event in WP Crontrol plugin
wp_remote_get(get_site_url().”/?c=1&ss_c=3326p5781w2f2drgq8j2″);
it’s configured properly and running every minute, but I’m not getting FTP (photos) processing and other maintenance actions
Any suggestion?
]]>Remote post: wp_remote_post() failed. Contact your hosting provider.
Remote get: wp_remote_get() failed. Contact your hosting provider.
Any advice on how to troubleshoot would be appreciated as the error message is pretty vague. (I am the hosting provider, in that my install is hosted on AWS – I can change all settings if anyone has any advice?)
I am running WordPress 5.2.1 with Woocommerce 3.6.3 on Nginx with PHP 7.3.5 and cURL version 7.61.1 OpenSSL/1.0.2k installed, all functioning as I would expect.
]]>First of all, thank you for the useful plugin.
We are very happy we don’t have to invent the wheel.
Unfortunately we found a problem with a timeout when one of our Sitemap XMLs takes too much time to load. The default timeout for the wp_remote_get
function is 5 seconds so we had to improve the parameters of the plugin locally to 10 seconds. It would be great if you can also introduce this improvement either via an option or just hardcoded.
Thank you!
I’m using wp_remote_get to basically interact with a remote server. It all works fine from my own WP install and even works on installs on 2 different laptops.
The error being reported is
“Response could not be parsed”
which digging into the WordPress code seems to suggest that the headers are missing.
The odd thing is that the wp_remote_get call is to this url:
https://canalplan.org.uk/cgi-bin/api.cgi?mode=version
And that server actually sees a call from the user’s wordpress install to the url – but its dying at the other end.
Is there any way of getting any better diagnostic information from the wp_remote_get error response?
]]>right now, I’m trying to develop my first plugin.
Because WordPress comes with its own HTTP-API, I want to switch from cURL (script was used as stand alone) to wp_remote_X, but I’m stuck and need your help.
While
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization: ' . $apikey, 'Accept: application/vnd.api+json'));
curl_setopt($ch, CURLOPT_URL,$url);
$result=curl_exec($ch);
curl_close($ch);
is working fine, I cannot “translate” it to the new wp_remote-thing:
$result = wp_remote_retrieve_body(wp_remote_get($url, array('sslverify' => false, 'headers' => array('Authorization: '. $apikey,'Accept: application/vnd.api+json'))));
Result should be some JSON data, but I always get a 451 – Unsupported Media Type
Hope you guys here can help me.
Thanks a lot!