本文整理汇总了C#中System.Net.Http.HttpClient.DoCommand方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.DoCommand方法的具体用法?C# HttpClient.DoCommand怎么用?C# HttpClient.DoCommand使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Net.Http.HttpClient
的用法示例。
在下文中一共展示了HttpClient.DoCommand方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
var apiClient = new HttpClient();
// apiClient.BaseAddress = new System.Uri("http://localhost:6357");
apiClient.BaseAddress = new System.Uri("http://localhost:18193");
var command = new ModifyCooperatorBasic
{
CooperatorID = "52b007cd9a37601480b6d5e6",
Name = "ivan",
Type = 0,
Remark = ""
};
var task = apiClient.DoCommand(command);
var result = task.Result.Content.ReadAsStringAsync().Result;
Console.Write(result);
}
示例2: Put
public Task<ApiResult> Put([FromBody]ICommand command)
{
if (ModelState.IsValid)
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(string.Format("{0}://{1}/api/command",
Request.RequestUri.Scheme,
Request.RequestUri.Authority));
return client.DoCommand<ApiResult>(command, null);
}
else
{
return Task.Factory.StartNew<ApiResult>(() =>
new ApiResult
{
ErrorCode = ErrorCode.CommandInvalid,
Message = string.Join(",", ModelState.Values
.SelectMany(v => v.Errors
.Select(e => e.ErrorMessage)))
});
}
}