php - 'Bad Request' when using 'wp_remote_post' in Wordpress
one text
<form method="post">
<input type="text" name="telNum"/> <br />
<input type="submit" value="continue" name="adslSubmit"/>
I have created the form above in index.php and want to make remote api call with wp_remote_post
function but when i var_dump it i get bad request.
if(isset($_POST["adslSubmit"])) {
$sum=$_POST["telNum"];
$body = [
'phone' => '02144365296',
];
$ApiUrl = "https://apis.mabnatelecom.com/api/inquiry";
$bodyRequest = array(
"headers"=>array(
'Content-Type' => 'application/json',
'Authorization' => 'Bearer 63428f4b7cb735b9d0d59f0bd539656f',
),
"body"=> $body,
);
$api_response = wp_remote_post($ApiUrl,$bodyRequest);
echo 'before';
var_dump($api_response);
echo 'after';
}
The way i should send data to api is:
{
"phone" : "02144365296"
}
Source