I made an api with nodejs
and i’m trying to make some calls to it throught wordpress, all the requests works correctly but when i add a request body it is sent empty, i tried to search what was the problem but i found nothing that worked.
I mean if i send this request
$body = (
'name' => 'Pixelbart',
'email' => 'pixelbart@example.com',
"password" => "Pass#your!word"
);
$body = json_encode( $body, TRUE );
echo $body; // here the body is correctly populated
$res = wp_remote_post("http://localhost:3000/users",
array(
'headers' => array(
'Origin' => "http://localhost"
),
'body' => $body,
'method' => 'POST',
'data_format' => 'body'
)
);
on the api side if i try to read the request body it is an empty JSON.
As i thought that was an api problem i tried to send the request with other tools but
if i use postman for send the reqeust in the same way it correctly works.
Am i missing something? I tried also to remove all the plugins and all the custom imports for have a clear enviroment but the same error happens
( Also ajax requesto from javascript fails if sent from the active wordpress theme )