当前位置: 首页>>代码示例>>C#>>正文


C# HttpClient.DeleteAsync方法代码示例

本文整理汇总了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();
     }
 }
开发者ID:CruzerBoon,项目名称:Prism-Samples-Windows,代码行数:8,代码来源:ShoppingCartServiceProxy.cs

示例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;
        }
开发者ID:igudelj,项目名称:AsyncTaskXamarin,代码行数:36,代码来源:AsyncRequest.cs

示例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);
            }

        }
开发者ID:smndtrl,项目名称:libtextsecure-uwp,代码行数:58,代码来源:PushServiceSocket.cs


注:本文中的HttpClient.DeleteAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。