我正在开发Xamarin.Android中的Android应用程序,我想使用RestSharp访问Web API(托管在本地IIS上)。当我运行应用程序时,它不会给出任何结果,也不会给出任何错误。
这是我的代码
var client = new RestClient("http://localhost:8066/Student/?id=193");
var request = new RestRequest("", Method.GET);
IRestResponse response = client.Execute(request);
var content = response.Content;
Console.WriteLine("Response: " + content);
答案 0 :(得分:1)
关注documentation,在创建RestClient时,您应该只提供基本网址。
var client = new RestClient("http://localhost:8066");
var request = new RestRequest("/Student", Method.GET);
request.AddParameter("id", "193");
IRestResponse response = client.Execute(request);
var content = response.Content;
Console.WriteLine("Response: " + content);