[c#]RestSharp 得到完整的 URL 的请求

标签: Asp.net .Net C#
发布时间: 2017/2/25 3:47:30
注意事项: 本文中文内容可能为机器翻译,如要查看英文原文请点击上面连接.

有一个办法让 RestSharp 请求包括其资源和查询字符串参数的完整 url 吗?

此请求的,即︰

RestClient client = new RestClient("http://www.some_domain.com");
RestRequest request = new RestRequest("some/resource", Method.GET);
request.AddParameter("some_param_name", "some_param_value", ParameterType.QueryString);

IRestResponse<ResponseData> response = client.Execute<ResponseData>(request);

我想要完整的请求 URL:

http://www.some_domain.com/some/resource?some_param_name=some_param_value

解决方法 1:

若要获取完整的 URL 使用RestClient.BuildUri()

具体来说,在此示例使用 client.BuildUri(request) :

RestClient client = new RestClient("http://www.some_domain.com");
RestRequest request = new RestRequest("some/resource", Method.GET);
request.AddParameter("some_param_name", "some_param_value", ParameterType.QueryString);

IRestResponse<ResponseData> response = client.Execute<ResponseData>(request);

var fullUrl = client.BuildUri(request);
赞助商