1

我有一段使用 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转换吗?

4

0 回答 0