小编Fri*_*man的帖子

Json Post 在 Postman 中有效,但在 C# 中无效

当我在 Postman 中尝试 Post 请求时,它给了我正确的响应,没有错误。当我使用 Postman 生成的 Restsharp 代码时,响应始终为空且没有错误。

var client = new RestClient("https://myurl/api/authenticate/authenticate");
        var request = new RestRequest(Method.POST);
        request.AddHeader("postman-token", "00497e4f-f58f-677d-f98a-bb972032c2eb");
        request.AddHeader("cache-control", "no-cache");
        request.AddHeader("content-type", "application/json");
        request.AddParameter("application/json", "{\n\t\"applicationKey\" : \"MYAPPLICATIONKEY\",\n\t\"userSecret\" : \"MYUSERSECRET\"\n}", ParameterType.RequestBody);
        IRestResponse response = client.Execute(request);
        Console.WriteLine(response.Content);
Run Code Online (Sandbox Code Playgroud)

我试图用 postman-token、cache-control 删除行,但总是一样没有错误没有响应。(在响应中我应该得到访问令牌)

c# json restsharp

2
推荐指数
1
解决办法
6896
查看次数

标签 统计

c# ×1

json ×1

restsharp ×1