wp_remote_get arguments not received
-
Hi,
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
- The topic ‘wp_remote_get arguments not received’ is closed to new replies.