I have a c# code that uses NameValueCollection, and then webclient to send a post request to API.
I need to use an equivalent request but using javascript instead of c#, I tried the following:
$.ajax({
type: "POST",
url: "https://api.pushover.net/1/messages.json",
contentType: "application/json; charset=utf-8",
dataType: "json",
data: {
"message": "xyz",
"token": "xyz",
"user": "xyz",
},
success: function(data) {
console.log("push sent!");
}
});
But I get a 400 error, stating "bad request".
Please ignore the security perspective as the token & user are available to the user.
c# code is:
var parameters = new NameValueCollection {
{ "token", "xyz" },
{ "user", "xyz" },
{ "message", "xyz" }
};
using (var client = new WebClient())
{
client.UploadValues("https://api.pushover.net/1/messages.json", parameters);
}