Restsharp not giving any response

2019-09-09 14:25发布

问题:

I am developing an Android app in Xamarin.Android and I want to access a Web API (hosted on local IIS) using RestSharp. When I run the app it doesn't give any result nor give any error.

Here is my code

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);

回答1:

Follow the documentation, when creating a RestClient you should just provide the base URL.

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);