Reputation: 153
I want to add my string username and password into the string jsonData however there seems to be an error.
public async Task<string> authLogin(string username, string password)
{
var client = new HttpClient();
client.BaseAddress = new Uri("http://172.20.129.193/");
string jsonData = @"{""AdminNo"" : """+username+""", """+password+""" : ""password""}";
var content = new StringContent(jsonData, Encoding.UTF8, "application/json");
HttpResponseMessage response = await client.PostAsync("NYPStudentLifeService/api/student/login",content);
string result = await response.Content.ReadAsStringAsync();
return result;
}
Upvotes: 1
Views: 5618
Reputation: 153
The way you are using is wrong try out this method. Also the password order was wrong as mentioned above. ^
Instead of:
string jsonData = @"{""AdminNo"" : """+username+""", ""password"" : """+password+"""}";
You can try out this:
string jsonData = @"{'AdminNo':'"+username+"','Password':'"+password+"'}";
Upvotes: 2
Reputation: 411
Use RestSharp for REST API calls and NewtoSoft to serialize your objects to JSONs. Your code is obsolete.
http://www.newtonsoft.com/json
By the way... your error is the order of "password"
You have
string jsonData = @"{""AdminNo"" : """+username+""", """+password+""" : ""password""}";
Should be
string jsonData = @"{""AdminNo"" : """+username+""", ""password"" : """+password+"""}";
Upvotes: 0