添加GET参数与RestSharp POST请求 [英] Add a GET parameter to a POST request with RestSharp

查看:1580
本文介绍了添加GET参数与RestSharp POST请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想打一个POST请求,像这样的网址:

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

http://localhost/resource?auth_token=1234

和我要在身体发出JSON。我的code看起来是这样的:

And I want to send JSON in the body. My code looks something like this:

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

我如何设置的auth_token 参数是一个GET参数,并请求为POST?

How can I set the auth_token parameter to be a GET parameter and make the request as POST?

推荐答案

这应该工作,如果你1)令牌添加到资源的URL和2)指定ParameterType.UrlSegment是这样的:

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.

这篇关于添加GET参数与RestSharp POST请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆