本文整理汇总了C#中RestClient.AddDefaultParameter方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.AddDefaultParameter方法的具体用法?C# RestClient.AddDefaultParameter怎么用?C# RestClient.AddDefaultParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestClient
的用法示例。
在下文中一共展示了RestClient.AddDefaultParameter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestOnlyDefaultParameter
public void TestOnlyDefaultParameter()
{
using (var client = new RestClient("http://localhost"))
{
client.AddDefaultParameter("param1", "value1");
var request = new RestRequest();
var uri = client.BuildUri(request).ToString();
Assert.Equal("http://localhost/?param1=value1", uri);
}
}
示例2: TestParameterOverride
public void TestParameterOverride()
{
using (var client = new RestClient("http://localhost"))
{
client.AddDefaultParameter("param1", "value1");
var request = new RestRequest();
request
.AddParameter("param2", "value2")
.AddOrUpdateParameter("param1", "value1.1");
var uri = client.BuildUri(request).ToString();
Assert.Equal("http://localhost/?param1=value1.1¶m2=value2", uri);
}
}
示例3: TestDefaultParameter
public async Task TestDefaultParameter(Type factoryType)
{
using (var client = new RestClient("http://httpbin.org/")
{
HttpClientFactory = CreateClientFactory(factoryType, false),
})
{
client.AddDefaultParameter("Restsharp-Test2", "TestValue2", ParameterType.HttpHeader);
var request = new RestRequest("post", Method.POST);
request.AddParameter("param1", "ParamValue1");
var response = await client.Execute<HttpBinResponse>(request);
Assert.Equal("ParamValue1", response.Data.Form["param1"]);
Assert.Equal("TestValue2", response.Data.Headers["Restsharp-Test2"]);
}
}
示例4: TestParameterCaseInsensitive
public void TestParameterCaseInsensitive()
{
using (var client = new RestClient("http://localhost")
{
DefaultParameterNameComparer = StringComparer.OrdinalIgnoreCase,
})
{
client.AddDefaultParameter("param1", "value1");
var request = new RestRequest();
request
.AddParameter("param2", "value2")
.AddParameter("Param1", "value1.1");
var uri = client.BuildUri(request).ToString();
Assert.Equal("http://localhost/?Param1=value1.1¶m2=value2", uri);
}
}