Add a GET parameter to a POST request with RestSharp

前端 未结 2 487
灰色年华
灰色年华 2020-12-15 05:38

I want to make a POST request to a URL like this:

http://localhost/resource?auth_token=1234

And I

2条回答
  •  温柔的废话
    2020-12-15 05:57

    This should work if you 1) add the token to the resource url and 2) specify ParameterType.UrlSegment like this:

    var client = new RestClient("http://localhost");
    var request = new RestRequest("resource?auth_token={authToken}", Method.POST);
    request.AddParameter("auth_token", "1234", ParameterType.UrlSegment);    
    request.AddBody(json);
    var response = client.Execute(request);
    

    This is far from ideal - but the simplest way I've found... still hoping to find a better way.

提交回复
热议问题