RestSharp post request - Body with x-www-form-urlencoded values

前端 未结 4 1967
抹茶落季
抹茶落季 2020-12-03 04:43

I am using postman and making an api post request where I am adding body with x-www-form-urlencoded key/values and it works fine in postman.

The issue arrises when I

4条回答
  •  孤城傲影
    2020-12-03 04:56

    Personally, I found AddObject() method quite useful, and cleaner when you have so many parameters to add.

    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 in request
    
            req.AddHeader("Content-Type","application/x-www-form-urlencoded");
            req.AddObject(config);
    
            var res = client.Execute(req);
            return res;
        }
    

提交回复
热议问题