PHP API POST with parameter body

Viewed 661

This is the documentation: documentation And this is the code that I use:

$response = wp_remote_post( 'https://services.daisycon.com/authenticate', array(
    'method' => 'POST',
    'timeout' => 45,
    'redirection' => 5,
    'httpversion' => '1.0',
    'blocking' => true,
    'headers' => array(),
    'body' => array( 'username' => $username, 'password' => $password),
    'cookies' => array()
    )
);

if ( is_wp_error( $response ) ) {
   $error_message = $response->get_error_message();
   echo "Something went wrong: $error_message";
} else {
   echo 'Response:<pre>';
   print_r( $response );
   echo '</pre>';
}

But it won't work, it gives me this:

[body] => {"error":"username is required"}
[response] => Array
    (
        [code] => 400
        [message] => Bad Request
    )

I really dont see the problem, please help me.

1 Answers
Related