我使用RestSharp的v130编写了一段非常简单的代码。代码本身编译得很好,并从服务器返回值 - 问题是它们不是我追求的那些。
代码
private void startTest()
{
string email = "bob2@example.com";
string password = "password";
doRestSharpWebRequest(email, password);
}
private void doRestSharpWebRequest(email, password)
{
var restClient = new RestClient();
restClient.BaseUrl = "https://mytestserver.com/api";
restClient.Authenticator = new SimpleAuthenticator("email", email, "password", password);
var restRequest = new RestRequest("token", Method.GET);
restRequest.AddHeader("Accepts", "application/json;version=1");
restRequest.AddHeader("Authorization", "apikey zyzyz");
restRequest.RequestFormat = DataFormat.Json;
IRestResponse<userlogin> response = restClient.Execute<userlogin>(restRequest);
}
其中userlogin只是一个要反序列化的类。
当我运行代码时,出现以下错误
Message = No HTTP resource was found that matches the request URI 'http://mytestserver.com/api/token?Email=bob%40example.com&password=password'.
有两件事是显而易见的,@已被更改为%40,这会导致问题并且http已更改为https。
可以告诉restsharp不要从https和http转换吗?