c# - xamarin form not calling web api using visual studio 2105 -


i want call web api(which on local visual studio) through xamarin forms not calling web api. using visual studio android emulator.

i using visual studio 2015 update 3 , here code

 public class dataservice {      httpclient client = new httpclient();     string apipaht = "http://10.0.2.2:19367/api/";     //string apipaht = "http://localhost:19367/api/";      public async task<list<customerapp>> gettodoitemsasync()     {         var response = await client.getstringasync(apipaht+ "apicustaccount/gettestdata");         var todoitems = jsonconvert.deserializeobject<list<customerapp>>(response);         return todoitems;     }  } 

code on xamal.cs

  async void refreshdata()     {         list<customerapp> listcust = await _dservice.gettodoitemsasync();                    todolist.itemssource = listcust;         string aa = "";     }     protected void btn_click(object sender, eventargs e)     {        refreshdata();     } 

hi please try below code , let me know if have query.

get method:

httpclient client = new httpclient(); client.baseaddress = new uri("http://10.0.2.2:19367/api/"); client.defaultrequestheaders.accept.add(new mediatypewithqualityheadervalue("application/json")); httpresponsemessage response = client.getasync("apicustaccount/gettestdata").result; if (response.statuscode == httpstatuscode.ok) {     var result = await response.content.readasstringasync();     var todoitems = jsonconvert.deserializeobject<list<customerapp>>(result); } 

i have tested above code , it's working me.


Comments

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -