如何从通用Windows应用程序中检索Rest Api中的数据?
问题描述:
我想通过URI将通用Windows应用程序的数据发送到休息API。如何从通用Windows应用程序中检索Rest Api中的数据?
如果是文字,我可以解决,很容易
string WebData = wc.DownloadString("http://restapic.azurewebsites.net/WebForm1.aspx?func=dd&hodn=WW")
但要怎么做,如果我想传递的价值如int或名称,我不知道?例如,我想在通用Windows应用程序中输入199号文本框,然后发送它。
我可以这样做:
string WebData = wc.DownloadString("http://restapic.azurewebsites.net/WebForm1.aspx?func=dd&hodn=WW&value="+myNumber)
但随后问我在此文件中的声明....
感谢。
答
您可以尝试如下。
HttpClient client = new HttpClient();
client.BaseAddress = new Uri("http://localhost:8880/");
HttpResponseMessage response = client.GetAsync("api/product/1").Result;