【问题标题】:RestSharp StatusCode vs IsSuccessfulRestSharp StatusCode vs IsSuccessful
【发布时间】:2022-03-15 06:55:37
【问题描述】:

我有以下课程

public class Customer 
{
    public Customer() 
    {
        Project = new HashSet<Project>();
    }

    public uint Id { get; set; }
    public string Name { get; set; }
    public string Address { get; set; }
    public string Phone { get; set; }
    
    public HashSet<Project> Project { get; set; }
}

还有下面的方法

protected async Task<IRestResponse> ApplyRequest<T>(string resource, 
    Method method, T data) where T: class, new() 
{
    var client = new RestClient(_connectionConfig.BaseUrl);
    
    client.FollowRedirects = false;
    
    var request = new RestRequest(resource, method);
    request.RequestFormat = RestSharp.DataFormat.Json;
    request.AddParameter("application/json",
        JsonConvert.SerializeObject(data), ParameterType.RequestBody);
        
    //request.AddJsonBody(data); 
    //This also doesn't work
    
    var response2 = await client.ExecuteTaskAsync<T>(request);
    
    return response2;
}

现在,如果我用 Post 方法调用此方法,返回状态码是“已创建”(实际上是已创建)。但是,属性 IsSuccessful 给出“false”并且错误消息是

“无法将 'SimpleJson.JsonArray' 类型的对象转换为类型 'System.Collections.Generic.IDictionary`2[System.String,System.Object]'。”

这是正常现象,还是我做错了什么? 谢谢

【问题讨论】:

    标签: c# .net restsharp


    【解决方案1】:

    它没有成功,因为你有一个序列化错误。我还看到你在 GiTHub 上记录了它并得到了相同的响应。 https://github.com/restsharp/RestSharp/issues/1064

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-10-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-04-01
      • 1970-01-01
      相关资源
      最近更新 更多