小编nic*_*v80的帖子

RestSharp发布请求 - 具有x-www-form-urlencoded值的正文

我正在使用邮递员并发出api post请求,其中我添加了x-www-form-urlencoded键/值的正文,它在邮递员中工作正常.

当我使用RestSharp软件包从c#中尝试它时,问题就出现了.

我在下面尝试了以下代码但没有得到响应.我收到"BadRequest"invalid_client错误.

public class ClientConfig {
    public string client_id { get; set; } = "value here";
    public string grant_type { get; set; } = "value here";
    public string client_secret { get; set; } = "value here";
    public string scope { get; set; } = "value here";
    public string response_type { get; set; } = "value here";
}

public void GetResponse() {
        var client = new RestClient("api-url-here");
        var req = new RestRequest("endpoint-here",Method.POST);
        var config = new ClientConfig();//values to pass …
Run Code Online (Sandbox Code Playgroud)

c# post restsharp

28
推荐指数
4
解决办法
2万
查看次数

标签 统计

c# ×1

post ×1

restsharp ×1