HTTPRequest
HTTPRequest copied to clipboard
Post requests don't work.
It does send the request to my web-server yes, but it does not include any data.
Logging "req.query" yields a result of an empty object, and when logging "req.body" it's undefined.
I've tried both examples, the form data and the json body and none of them work.
For example, this is the example for JSON body
try {
http::Request request{ "http://0.0.0.0/get-confirmations" };
const std::string body = "{ \"shared_secret\": \"" + account.shared_secret + "\", \"identity_secret\": \"" + account.identity_secret + "\" }";
const auto response = request.send("POST", body, {
{"Content-Type", "application/json"}
});
std::cout << std::string{ response.body.begin(), response.body.end() } << '\n'; // print the result
} catch (const std::exception& e) {
std::cerr << "Request failed, error: " << e.what() << '\n';
}
This is how my web-server is setup atm, just a simple express api
app.post('/get-confirmations', (req, res) => {
console.log("query", req.query);
console.log("body", req.body);
const { shared_secret, identity_secret } = req.query;
if (!shared_secret || !identity_secret) {
return res.status(400).send('Missing shared_secret or identity_secret');
}
return res.send('Hello world | Shared Secret: ' + shared_secret + ' | Identity Secret: ' + identity_secret);
});
What am I doing wrong?
same issue here, didnt find a fix