Skip to main content
OverflowAI is here! AI power for your Stack Overflow for Teams knowledge community. Learn more
36 votes

Sending JSON string through wp_remote_post()

Try setting the data_format parameter in your request like so: $data = wp_remote_post($url, array( 'headers' => array('Content-Type' => 'application/json; charset=utf-8'), 'body' ...
phatskat's user avatar
  • 3,144
12 votes

Error timed out with succesfull wp_remote_post

You can set the timeout directly in the wp_remote_post() $args, as per this example from $response = wp_remote_post( $url, array( 'method' => 'POST', 'timeout'...
Tom Auger's user avatar
  • 7,046
5 votes

How do I get URL from WP_HTTP object?

I'm not sure what you're after here, but you can try to get the HTTP response object from the WP_HTTP_Requests_Response::get_response_object() method. Here's an example to retrieve the url: if( ...
birgire's user avatar
  • 67.3k
5 votes

How to run multiple Async HTTP requests in Wordpress?

The (built-in) Requests class lets you call multiple requests simultaneously: Requests::request_multiple. <?php $requests = Requests::request_multiple([ [ 'url' => 'https://www....
alpipego's user avatar
  • 356
4 votes

Difference between wp_remote_post and wp_safe_remote_post

So is there ever any other situation in which I would want to use wp_remote_post or should I always stick with wp_safe_remote_post? The two functions are exactly the same, except wp_safe_remote_post()...
Nathan Johnson's user avatar
3 votes

How to duplicate a curl XML request using HTTP API?

I tried some more trial and error and managed to get it to work by simply putting $xml as the body without specifying it as an array. The function reference says, "Post data should be sent in the body ...
Jason's user avatar
  • 76
3 votes

WP_Http response throws "Cannot use object of type WP_Error as array"

Your logic for your updated if statement is wrong. if( !is_wp_error($response) && $response['response']['code'] != 200 ) Here you are saying; if NOT wp_error AND response code NOT 200 return ...
ngearing's user avatar
  • 2,144
3 votes

How to convert this cURL to wp_remote_get?

The curl is sending a POST request, to convert this you'll want to use wp_remote_post(). As described in the documentation, the request arguments are the same as WP_Http::request(), so let's look ...
kero's user avatar
  • 6,210
3 votes

Allow download_url for lan addresses

to allow this IP as safe, use this filter add_filter("http_request_host_is_external", function ($is, $host, $url) { if ("" === $host) { $is = TRUE; } return $is; }, ...
mmm's user avatar
  • 3,704
2 votes

How to use WordPress HTTP API to download file from remote location

$your_pdf_path = ''; if (!class_exists('WP_Http')) include_once( ABSPATH . WPINC . '/class-http.php' ); $http = new WP_Http(); $response = $http->...
mujuonly's user avatar
  • 164
2 votes

Save external API calls in WordPress

Mark, I've had to do something similar for multiple jobs. This is a larger topic but I'll try break it down in steps and hopefully gets you going in the right direction. I've broken the code into ...
Tom's user avatar
  • 1,286
2 votes

How to set charset for wp_remote_post request?

After trying several times to set the proper charset, I wasn't successful. Then I searched for an workaround and found one that worked with my problem. In addition to set the charset like I ...
Diego de Oliveira's user avatar
2 votes

Difference between wp_remote_post and wp_safe_remote_post

the _safe_ functions are kind of a late attempt at input sanitation, something that should have happened long before the code have reached that point. (at that point the request will fail without any ...
Mark Kaplun's user avatar
  • 23.4k
2 votes

wp_http remote request not respecting timeout

I suspect this is the cause in the Requests library that powers WP_HTTP: Transfer & connect timeouts, in seconds & milliseconds cURL is unable to handle timeouts under a second in DNS ...
Tom J Nowell's user avatar
  • 59.4k
2 votes

How to use the HTTP API (wp_remote_get) instead of cURL?

So it looks like I've managed to fix my own problem here. I don't know if this is the best thinkable solution to this exact problem, but it does work! My assumptions about CURLOPT_FOLLOWLOCATION seem ...
DeltaG's user avatar
  • 899
2 votes

External HTTP API calls slowing down Wordpress admin

You can block/allow external requests if you like, using a combination of WP_HTTP_BLOCK_EXTERNAL and WP_ACCESSIBLE_HOSTS. Here is the note from /wp-includes/class-http.php: /** * Block requests ...
majick's user avatar
  • 5,081
1 vote

Send a get request to wordpress

One option would be to create a Page dedicated to processing these GET requests. Something like`. You can then create a page template, either page-...
WebElaine's user avatar
  • 9,430
1 vote

wp_remote_post empty $_POST

Ok, found the problem: I didn't have to json_encode the body.
Dany92's user avatar
  • 11
1 vote

Cache WP remote_get HTTP Response using Transients

function display_api_response() { $body = get_transient( 'my_remote_response_value' ); if ( false === $body ) { $api_url = ""; ...
Hector's user avatar
  • 671
1 vote

Sending JSON Payload using Request::request_multiple()

You can't. The requests library that comes bundled in WordPress doesn't support this. The reason for this is that the request_multiple function only accepts these parameters: * @param array $requests ...
Tom J Nowell's user avatar
  • 59.4k
1 vote

Return WP_Error as WP_REST_Response

Already found, if I parse the response response.json() I get the messages in both cases
GWorking's user avatar
  • 165
1 vote

Why does WP HTTP API switch the method (POST/PURGE) to GET when redirecting (302)?

The change of method to GET after redirect from POST, PURGE, BAN whatever, is perfectly legal and been there, and will be without Wordpress (it has nothing to do with it, really). Welcome to the World ...
Danila Vershinin's user avatar
1 vote

wp remote post getting a 404 error code

I solved it by changing the method to PUT & httpversion to 1.1
Debu's user avatar
  • 21
1 vote

How to consume and display external data in WordPress from another website

// make request... (optionally save in transient for faster future fetches) $dom = new DOMDocument(); $dom->loadHTML(wp_remote_retrieve_body($request)); $sections=$dom->getElementsByTagName(&...
Shivanand Sharma's user avatar
1 vote

Mutual Authentiction on HTTPS with Wordpress HTTP API?

Re the WP HTTP API look for the sslverify and sslcertificates args in this docs page: sslverify defaults to true and sslcertificates ...
firxworx's user avatar
  • 241

Only top scored, non community-wiki answers of a minimum length are eligible