本文整理汇总了C#中HttpClient.PutAsJsonAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.PutAsJsonAsync方法的具体用法?C# HttpClient.PutAsJsonAsync怎么用?C# HttpClient.PutAsJsonAsync使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient.PutAsJsonAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Process
private async static void Process()
{
//获取当前联系人列表
HttpClient httpClient = new HttpClient();
HttpResponseMessage response = await httpClient.GetAsync("http://localhost/selfhost/api/contacts");
IEnumerable<Contact> contacts = await response.Content.ReadAsAsync<IEnumerable<Contact>>();
Console.WriteLine("当前联系人列表:");
ListContacts(contacts);
//添加新的联系人
Contact contact = new Contact { Name = "王五", PhoneNo = "0512-34567890", EmailAddress = "[email protected]" };
await httpClient.PostAsJsonAsync<Contact>("http://localhost/selfhost/api/contacts", contact);
Console.WriteLine("添加新联系人“王五”:");
response = await httpClient.GetAsync("http://localhost/selfhost/api/contacts");
contacts = await response.Content.ReadAsAsync<IEnumerable<Contact>>();
ListContacts(contacts);
//修改现有的某个联系人
response = await httpClient.GetAsync("http://localhost/selfhost/api/contacts/001");
contact = (await response.Content.ReadAsAsync<IEnumerable<Contact>>()).First();
contact.Name = "赵六";
contact.EmailAddress = "[email protected]";
await httpClient.PutAsJsonAsync<Contact>("http://localhost/selfhost/api/contacts/001", contact);
Console.WriteLine("修改联系人“001”信息:");
response = await httpClient.GetAsync("http://localhost/selfhost/api/contacts");
contacts = await response.Content.ReadAsAsync<IEnumerable<Contact>>();
ListContacts(contacts);
//删除现有的某个联系人
await httpClient.DeleteAsync("http://localhost/selfhost/api/contacts/002");
Console.WriteLine("删除联系人“002”:");
response = await httpClient.GetAsync("http://localhost/selfhost/api/contacts");
contacts = await response.Content.ReadAsAsync<IEnumerable<Contact>>();
ListContacts(contacts);
}
示例2: UpdateBalanz
private async Task UpdateBalanz(string RekeningID, int nbalans)
{
System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls;
using (var client = new HttpClient(new HttpClientHandler { UseProxy = false, ClientCertificateOptions = ClientCertificateOption.Automatic }))
{
client.BaseAddress = new Uri("https://hrsqlapp.tk");
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
HTTPget tmp = new HTTPget();
Rekening uploadobject = tmp.getRekening(RekeningID);
uploadobject.balans = nbalans;
HttpResponseMessage response = await client.PutAsJsonAsync(String.Concat("/api/rekenings/", RekeningID), uploadobject).ConfigureAwait(false);
if (response.IsSuccessStatusCode)
{
//Error.show("SUCCES");
}
else
{
//Error.show("FAIL");
}
}
}