ZenDesk使用RestSharp时出现错误:名称太短

本文关键字:错误 使用 RestSharp ZenDesk | 更新日期: 2023-09-27 18:03:19

当我尝试运行下面的代码时,我有错误代码:名称太短(最小是1个字符)。我使用RestSharp v104.1。当我试图创建一个新用户时,如果我尝试阅读,我不会遇到任何问题。

static string requestUri = "https://subdomain.zendesk.com/api/v2";
    static string username = "myusername";
    static string password = "mypassword";
    static void Main(string[] args)
    {
        string new_users = "{'"user'":{ '"id'":4000000001, '"name'":'"Robin 001'", '"email'":'"robin.001@company.com'" }}";
        Console.WriteLine(WriteJSON(username, password, "/users.json", new_users));
        Console.ReadLine();
    }
    public static string WriteJSON(string username, string password, string json, string to_write)
    {
        var client = new RestClient(requestUri);
        client.Authenticator = new HttpBasicAuthenticator(username, password);
        client.AddDefaultHeader("Content-type", "application/json");
        client.UserAgent = "MozillaXYZ/1.0";
        client.FollowRedirects = true;
        client.MaxRedirects = 10;
        var request = new RestRequest(json);
        request.Method = Method.POST;
        request.RequestFormat = DataFormat.Json;
        request.AddBody(to_write);
        IRestResponse response = client.Execute(request);
        var content = response.Content;
        System.Xml.Linq.XNode node = JsonConvert.DeserializeXNode(content, "root");
        return node.ToString();
    }

ZenDesk使用RestSharp时出现错误:名称太短

我在另一个地方发布了同样的问题,这里是帮助我的答案:https://github.com/restsharp/RestSharp/issues/535 issuecomment - 43373031