I have a question regarding httpclient, i have a node.js rest api and Im trying to post (send) the user info to the service in order to insert to a database. the service is ok i tested manually and with postman.
But im using vs2017 xamarin and to consume the information im using the httpclient
I convert my user object to a json format
var json = JsonConvert.SerializeObject(user);
result: {"userName":"user","email":"user@hot.com","psw":"jok"}
then I create a content string type and pass the json:
var content = new StringContent(json, Encoding.UTF8, "application/json");
then I create the client
var client = new HttpClient();
and i test the following two codes
if i use this code the service work and the data is inserted in the data base but i think is because im like manually passing the parameters
HttpResponseMessage response = await client.PostAsync("http://localhost/ws/postUser/"+ e.userName + "/" + e.email + "/" + e.psw, content);
but what i was expecting is that this code works but in the server im getting the error that the url is not find. I think i need to map the parameters with the content
HttpResponseMessage response = await client.PostAsync("http://localhost/ws/postUser/", content);
The URL of the service is
http://localhost/ws/postUser/:userName/:email/:psw
this is the complete code: I have a OnSignUpEventArgs class that inherit from EventArgs and where i declare the user object.
private async void SigUpDialog_mOnSigUpComplete(object sender, OnSignUpEventArgs e)
{
var json = JsonConvert.SerializeObject(e);
var content = new StringContent(json, Encoding.UTF8, "application/json");
var client = new HttpClient();
HttpResponseMessage response = await client.PostAsync("http://localhost/ws/postGasUser/"+ e.userName + "/" + e.email + "/" + e.psw, content);
// HttpResponseMessage response = await client.PostAsync("http://localhost/ws/postGasUser/", content);
if (response.IsSuccessStatusCode)
{
Console.Write("Success");
}
else
{
Console.Write("Error");
}
}