How to get the generated query string of wp_remote_get?

While the other answers are pretty good in providing an answer to your question (how to get the generated url), i will answer what i guess you really want to know (how do i get it to call thirdparty.com?foo=bar with wp_remote_get)

The Answer is: the $args array you use to transmit the url parameters won’t work like this. If you have to transmit a POST request with wp_remote_post, you would use the body argument like your example. However, to wp_remote_get thirdparty.com?foo=bar, you simply do

wp_remote_get('http://thirdparty.com?foo=bar');

if you want to get fancy and use an array, you can also do this:

$url = "http://thirdparty.com";
$data = array('foo' => 'bar');
$query_url = $url.'?'.http_build_query($data);
$response = wp_remote_get($query_url);

Happy Coding!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)