HttpRequest httpRequest = new HttpRequest();
RequestParams reqParams = new RequestParams { };
httpRequest.IgnoreProtocolErrors = true;
reqParams["data"] = "{\"path\": \"/Prime_Numbers.txt\"}";
httpRequest.AddHeader("Authorization", " Bearer MYKEY");
httpRequest.AddHeader("Content-Type", "application/json");
Console.WriteLine(httpRequest.Post("https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings", reqParams).ToString());我得到了以下错误:调用API函数“共享/创建_共享_链接_with”中的错误:请求主体:未能将输入解码为JSON。我正在使用dropbox。
我看到了下面的内容:https://github.com/csharp-leaf/Leaf.xNet/issues/66 (有人有类似的问题,但是这个修复没有起作用)
发布于 2022-01-29 11:13:13
当您使用RequestParams时,这意味着Context-Type: application/x-www-form-urlencoded。
您不能通过Content-Type通过.AddHeader()设置.Post(url, json, contentType),请为.Post(url, json, contentType)方法使用如下参数:
HttpRequest httpRequest = new HttpRequest();
httpRequest.AddHeader("Authorization", " Bearer MYKEY");
string url = "https://api.dropboxapi.com/2/sharing/create_shared_link_with_settings";
string jsonData = "{\"path\": \"/Prime_Numbers.txt\"}";
string response = httpRequest.Post(url, jsonData, "application/json").ToString();
Console.WriteLine(response);https://stackoverflow.com/questions/70483157
复制相似问题