首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Leaf.XNet C#把身体当作Json不工作

Leaf.XNet C#把身体当作Json不工作
EN

Stack Overflow用户
提问于 2021-12-25 22:35:24
回答 1查看 931关注 0票数 1
代码语言:javascript
复制
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 (有人有类似的问题,但是这个修复没有起作用)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 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)方法使用如下参数:

代码语言:javascript
复制
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);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70483157

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档