本文整理汇总了C#中HttpClient.DeleteAsync方法的典型用法代码示例。如果您正苦于以下问题:C# HttpClient.DeleteAsync方法的具体用法?C# HttpClient.DeleteAsync怎么用?C# HttpClient.DeleteAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HttpClient
的用法示例。
在下文中一共展示了HttpClient.DeleteAsync方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DeleteShoppingCartAsync
public async Task DeleteShoppingCartAsync(string shoppingCartId)
{
using (var shoppingCartClient = new HttpClient())
{
var response = await shoppingCartClient.DeleteAsync(new Uri(_shoppingCartBaseUrl + shoppingCartId));
response.EnsureSuccessStatusCode();
}
}
示例2: GetFromWebWinPhone
/// <summary>
/// Executes a HTTP request for Windows phone based device
/// </summary>
/// <param name="body">body of the request</param>
/// <returns>Array of bytes</returns>
private async Task<byte[]> GetFromWebWinPhone(byte[] body)
{
HttpClient request = new HttpClient();
Uri connectionUri = new Uri(_url);
HttpFormUrlEncodedContent formContent = null;
if (body != null && body.Length > 0)
formContent = new HttpFormUrlEncodedContent(_body);
HttpResponseMessage response = null;
if (_method.Equals(AsyncRequest.Get))
response = await request.GetAsync(connectionUri);
if (_method.Equals(AsyncRequest.Post))
response = await request.PostAsync(connectionUri, formContent);
if (_method.Equals(AsyncRequest.Put))
response = await request.PutAsync(connectionUri, formContent);
if (_method.Equals(AsyncRequest.Delete))
response = await request.DeleteAsync(connectionUri);
IBuffer stream = await response.Content.ReadAsBufferAsync();
byte[] readstream = new byte[stream.Length];
using (var reader = DataReader.FromBuffer(stream))
reader.ReadBytes(readstream);
request.Dispose();
response.Dispose();
return readstream;
}
示例3: getConnection
private async Task<HttpResponseMessage> getConnection(String urlFragment, String method, String body)
{
try
{
Uri url = new Uri(String.Format("{0}{1}", serviceUrl, urlFragment));
HttpClient connection = new HttpClient();
var headers = connection.DefaultRequestHeaders;
if (credentialsProvider.GetPassword() != null)
{
headers.Add("Authorization", getAuthorizationHeader());
}
if (userAgent != null)
{
headers.Add("X-Signal-Agent", userAgent);
}
HttpStringContent content;
if (body != null)
{
content = new HttpStringContent(body, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json");
Debug.WriteLine(body);
}
else
{
content = new HttpStringContent("");
}
switch (method)
{
case "POST":
return await connection.PostAsync(url, content);
case "PUT":
return await connection.PutAsync(url, content);
case "DELETE":
return await connection.DeleteAsync(url);
case "GET":
return await connection.GetAsync(url);
default:
throw new Exception("Unknown method: " + method);
}
}
catch (UriFormatException e)
{
throw new Exception(string.Format("Uri {0} {1} is wrong", serviceUrl, urlFragment));
}
catch (Exception e)
{
Debug.WriteLine(string.Format("Other exception {0}{1} is wrong", serviceUrl, urlFragment));
throw new PushNetworkException(e);
}
}