post - Xamarin - C# - HttpClient -


i have question regarding httpclient, have node.js rest api , im trying post (send) user info service in order insert database. service ok tested manually , postman.

but im using vs2017 xamarin , consume information im using httpclient

i convert user object json format

var json = jsonconvert.serializeobject(user);

result: {"username":"user","email":"user@hot.com","psw":"jok"}

then create content string type , pass json:

var content = new stringcontent(json, encoding.utf8, "application/json");

then create client

var client = new httpclient();

and test following 2 codes

if use code service work , data inserted in data base think because im manually passing parameters

httpresponsemessage response = await client.postasync("http://localhost/ws/postuser/"+ e.username + "/" + e.email + "/" + e.psw, content);

but expecting code works in server im getting error url not find. think need map parameters content

httpresponsemessage response = await client.postasync("http://localhost/ws/postuser/", content);

the url of service

http://localhost/ws/postuser/:username/:email/:psw

this complete code: have onsignupeventargs class inherit eventargs , declare 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");          }         } 


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -