0

I'm using wp_remote_post() for POST WordPress posts to external api, but it shows below error:

WP_Error Object ( [errors] => Array ( [http_request_failed] => Array ( [0] => cURL error 7: Failed to connect to XXX.XXX.X.XXX port 3000: Connection timed out ) ) [error_data] => Array ( ) )

Here is the code that I have used:

function backend_get_post($post_id, $author_id) {
    $user_id = get_field('user_id', 'user_'.$author_id);
    $data = array('userId' => $user_id, 'action' => 'update');
    $url = 'http://XXX.XXX.X.XXX:3000/api/articles/wordpress-webhook/' . $post_id;

    $response = wp_remote_post( $url, array(
      'method' => 'POST',
      'timeout' => 45,
      'redirection' => 5,
      'httpversion' => '1.0',
      'blocking' => true,
      'headers' => array(),
      'body' => $data,
      'cookies' => array()
       )
    );
    print_r($response);
}
add_action( 'publish_post', 'on_publish_post', 10, 2 );
  • I'm not sure what we can add to the error message: WordPress can't connect to the other server. Either the address is wrong, or the other server is down, or there's some firewall or access issue between the two, or maybe even WordPress is running without some proxy configuration even if other users on the server have it. Does the API respond to other requests? Can you connect to it from the same server you're running WordPress on? – Rup Mar 20 at 9:08
  • Okay @Rup just resolved by removing 'blocking' => true, but now got an error with cURL error 28: Operation timed out after 10000 milliseconds with 0 bytes received – Shadow Mar 20 at 9:13
  • That still sounds like a connection problem. I don't think removing blocking has fixed anything, just delayed / changed the error. – Rup Mar 20 at 9:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.