我有以下网址http://example-api.com/userid/1234 如何将 1234 路径参数添加到我的 URL 中。
RestRequest 类具有 AddParameter 和 ParameterType,但我没有看到路径参数的任何选项
RestRequest.AddParameter(value, ParameterType.);
使用
AddUrlSegment()
https://restsharp.dev/usage.html#url-segment
var myParamValue = "1234"
var request = new RestRequest("http://example-api.com/userid/{myParam}")
.AddUrlSegment("myParam", myParamValue);
// 基于 v112.x 的代码片段
var client = new RestClient(_baseUrl);
var path = "/path";
var request = new RestRequest(path, Method.Post);
var body = new
{
Parameter = "thing 1"
};
request.RequestFormat = DataFormat.Json;
request.AddJsonBody(body);
var result = await client.ExecuteAsync(request);
if (result.StatusCode == System.Net.HttpStatusCode.OK)
{
return result.Data;
}
else
{
// Something went wrong.
}