I am trying to post values to server authenticate method http://*/Token . From my C# client i get 400 Bad request error. While it works fine in jquery.
jQuery Code:
$( "#post2").click(function() {
var Email=$('#Email').val();
var Password=$('#Password').val();
$.ajax({
type:"Post",
url: "http://***/Token",
data:{
"grant_type": "password",
"username": Email,
"password": Password
},
success: function(msg)
{
user=msg["access_token"];
console.log(JSON.stringify(msg));
}
});
});
C# code
string email = "***@gmail.com";
string password = "***";
var tok = new TokenModel{grant_type = "password", username = email, password = password};
var s = JsonConvert.SerializeObject (tok);
var request = HttpWebRequest.Create (string.Format (@"http://***/Token", ""));
request.ContentType = "application/json";
request.Method = "POST";
using (var writer = new StreamWriter (request.GetRequestStream ())) {
writer.Write (s);
}
using (HttpWebResponse responses = request.GetResponse () as HttpWebResponse) {
}
I also tried by creating local json
var x = new
{
grant_type = "password",
username = "****@gmail.com",
password = "***"
};
But still the same error.
Is there anything i should do extra for making this call to server from C# client?
Please help, Thanks