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


C# System.Net.Http.HttpClient.SendAsync方法代码示例

本文整理汇总了C#中System.Net.Http.HttpClient.SendAsync方法的典型用法代码示例。如果您正苦于以下问题:C# System.Net.Http.HttpClient.SendAsync方法的具体用法?C# System.Net.Http.HttpClient.SendAsync怎么用?C# System.Net.Http.HttpClient.SendAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Net.Http.HttpClient的用法示例。


在下文中一共展示了System.Net.Http.HttpClient.SendAsync方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: FromBodyTestAsync

     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task FromBodyTestAsync(GeoPoint location, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}", BaseUrl, "api/Geo/FromBodyTest");
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(location, new Newtonsoft.Json.JsonConverter[] { new Newtonsoft.Json.Converters.StringEnumConverter(), new JsonExceptionConverter() }));
 			content_.Headers.ContentType.MediaType = "application/json";
 			request_.Content = content_;
 			request_.Method = new System.Net.Http.HttpMethod("POST");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "204") 
 			{
 				return;
 			}
 			else
 			if (status_ != "200" && status_ != "204")
 				throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null);
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:30,代码来源:ServiceClients.cs

示例2: UpdateZone

        /// <summary>
        /// status information to the smart things zone
        /// </summary>
        /// <param name="zoneInfo"></param>
        public static void UpdateZone(ZoneInfo zoneInfo)
        {
            try
            {
                OauthInfo authInfo = OauthRepository.Get();

                string url = authInfo.endpoints[0].uri + $"/UpdateZone";

                var client = new System.Net.Http.HttpClient();

                System.Net.Http.HttpRequestMessage msg = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, url);
                msg.Headers.Add("Authorization", $"Bearer {authInfo.accessToken}");

                List<KeyValuePair<string, string>> parms = new List<KeyValuePair<string, string>>();
                parms.Add(new KeyValuePair<string, string>("Id", zoneInfo.Id.ToString()));
                parms.Add(new KeyValuePair<string, string>("Status", zoneInfo.Status));
                parms.Add(new KeyValuePair<string, string>("Name", zoneInfo.Name));
                msg.Content = new System.Net.Http.FormUrlEncodedContent(parms);
                var response = client.SendAsync(msg);
                response.Wait();

                if (response.Result.StatusCode != System.Net.HttpStatusCode.Created)
                {
                    MyLogger.LogError($"Error updating smart things zone {zoneInfo.Id} with status {zoneInfo.Status}");
                }
            }
            catch (Exception ex)
            {
                MyLogger.LogError($"Error updating smart things zone {zoneInfo.Id} with status {zoneInfo.Status}.  Exception was {MyLogger.ExMsg(ex)}");
            }
        }
开发者ID:R-OG,项目名称:j64.AlarmServer,代码行数:35,代码来源:SmartThingsRepository.cs

示例3: ProductsAsync

     /// <summary>Product Types</summary>
     /// <param name="latitude">Latitude component of location.</param>
     /// <param name="longitude">Longitude component of location.</param>
     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <returns>An array of products</returns>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task<System.Collections.ObjectModel.ObservableCollection<Product>> ProductsAsync(double latitude, double longitude, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}?", BaseUrl, "products");
 
         if (latitude == null)
             throw new System.ArgumentNullException("latitude");
         else
             url_ += string.Format("latitude={0}&", System.Uri.EscapeDataString(latitude.ToString()));
 
         if (longitude == null)
             throw new System.ArgumentNullException("longitude");
         else
             url_ += string.Format("longitude={0}&", System.Uri.EscapeDataString(longitude.ToString()));
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			request_.Method = new System.Net.Http.HttpMethod("GET");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "200") 
 			{
 				var result_ = default(System.Collections.ObjectModel.ObservableCollection<Product>); 
 				try
 				{
 					if (responseData_.Length > 0)
 						result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.ObjectModel.ObservableCollection<Product>>(System.Text.Encoding.UTF8.GetString(responseData_, 0, responseData_.Length));                                
 					return result_; 
 				} 
 				catch (System.Exception exception) 
 				{
 					throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, exception);
 				}
 			}
 			else
 			{
 				var result_ = default(Error); 
 				try
 				{
 					if (responseData_.Length > 0)
 						result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<Error>(System.Text.Encoding.UTF8.GetString(responseData_, 0, responseData_.Length));
 
 				} 
 				catch (System.Exception exception_) 
 				{
 					throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, exception_);
 				}
 
 				throw new SwaggerException<Error>("Unexpected error", status_, responseData_, result_, null);
 			}
 		
 			return default(System.Collections.ObjectModel.ObservableCollection<Product>);
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:66,代码来源:UberClient.cs

示例4: DeleteAsync

     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task DeleteAsync(System.Guid id, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}", BaseUrl, "api/Persons/{id}");
 
         if (id == null)
             throw new System.ArgumentNullException("id");
         url_ = url_.Replace("{id}", System.Uri.EscapeDataString(id.ToString()));
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			request_.Method = new System.Net.Http.HttpMethod("DELETE");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "204") 
 			{
 				return;
 			}
 			else
 			if (status_ != "200" && status_ != "204")
 				throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null);
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:31,代码来源:ServiceClients.cs

示例5: Find2Async

     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task<System.Collections.ObjectModel.ObservableCollection<Person>> Find2Async(Gender? gender, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}?", BaseUrl, "api/Persons/find2");
 
         if (gender != null)
             url_ += string.Format("gender={0}&", System.Uri.EscapeDataString(gender.Value.ToString()));
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			var content_ = new System.Net.Http.StringContent(string.Empty);
 			request_.Content = content_;
 			request_.Method = new System.Net.Http.HttpMethod("POST");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "200") 
 			{
 				var result_ = default(System.Collections.ObjectModel.ObservableCollection<Person>); 
 				try
 				{
 					if (responseData_.Length > 0)
 						result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<System.Collections.ObjectModel.ObservableCollection<Person>>(System.Text.Encoding.UTF8.GetString(responseData_, 0, responseData_.Length), new Newtonsoft.Json.JsonConverter[] { new Newtonsoft.Json.Converters.StringEnumConverter(), new JsonExceptionConverter() });                                
 					return result_; 
 				} 
 				catch (System.Exception exception) 
 				{
 					throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, exception);
 				}
 			}
 			else
 			if (status_ != "200" && status_ != "204")
 				throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null);
 		
 			return default(System.Collections.ObjectModel.ObservableCollection<Person>);
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:44,代码来源:ServiceClients.cs

示例6: UpdatePetWithFormAsync

     /// <summary>Updates a pet in the store with form data</summary>
     /// <param name="petId">ID of pet that needs to be updated</param>
     /// <param name="name">Updated name of the pet</param>
     /// <param name="status">Updated status of the pet</param>
     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task UpdatePetWithFormAsync(int petId, string name, string status, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}", BaseUrl, "pet/{petId}");
 
         if (petId == null)
             throw new System.ArgumentNullException("petId");
         url_ = url_.Replace("{petId}", System.Uri.EscapeDataString(petId.ToString()));
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			var content_ = new System.Net.Http.MultipartFormDataContent();
 			if (name != null)
 				content_.Add(new System.Net.Http.StringContent(name.ToString()), "name");
 			if (status != null)
 				content_.Add(new System.Net.Http.StringContent(status.ToString()), "status");
 			request_.Content = content_;
 			request_.Method = new System.Net.Http.HttpMethod("POST");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "405") 
 			{
 				throw new SwaggerException("Invalid input", status_, responseData_, null);
 			}
 			else
 			if (status_ != "200" && status_ != "204")
 				throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null);
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:41,代码来源:PetStoreClient.cs

示例7: Authorized

        public IActionResult Authorized(string code)
        {
            OauthInfo oai = OauthRepository.Get();

            if (code == null)
                return View(oai);

            oai.authCode = code;

            System.Net.Http.HttpClient client = new System.Net.Http.HttpClient();

            var url = "https://graph.api.smartthings.com/oauth/token";

            List<KeyValuePair<string, string>> parms = new List<KeyValuePair<string, string>>();
            parms.Add(new KeyValuePair<string, string>("grant_type", "authorization_code"));
            parms.Add(new KeyValuePair<string, string>("code", oai.authCode));
            parms.Add(new KeyValuePair<string, string>("client_id", oai.clientKey));
            parms.Add(new KeyValuePair<string, string>("client_secret", oai.secretKey));
            string authorizedUrl = "http://" + this.Request.Host.Value + this.Url.Content("~/OAuth/Authorized");
            parms.Add(new KeyValuePair<string, string>("redirect_uri", authorizedUrl));

            var content = new System.Net.Http.FormUrlEncodedContent(parms);
            var response = client.PostAsync(url, content);
            response.Wait();

            if (response.Result.StatusCode != System.Net.HttpStatusCode.OK)
            {
                ViewData.Add("GetTokenError", "Get Auth Code Error: " + response.Result.StatusCode.ToString());
                return View(oai);
            }

            // Save the interim result
            var val = JsonConvert.DeserializeObject<Dictionary<string, string>>(response.Result.Content.ReadAsStringAsync().Result);
            oai.accessToken = val["access_token"];
            oai.expiresInSeconds = Convert.ToInt32(val["expires_in"]);
            oai.tokenType = val["token_type"];
            OauthRepository.Save(oai);

            // Get the endpoint info
            client = new System.Net.Http.HttpClient();
            url = "https://graph.api.smartthings.com/api/smartapps/endpoints";

            System.Net.Http.HttpRequestMessage msg = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Get, url);
            msg.Headers.Add("Authorization", $"Bearer {oai.accessToken}");

            response = client.SendAsync(msg);
            response.Wait();

            if (response.Result.StatusCode != System.Net.HttpStatusCode.OK)
            {
                ViewData.Add("GetTokenError", "Get EndPoints Error: " + response.Result.StatusCode.ToString());
                return View(oai);
            }

            string jsonString = response.Result.Content.ReadAsStringAsync().Result;
            oai.endpoints = JsonConvert.DeserializeObject<List<OauthEndpoint>>(jsonString);

            OauthRepository.Save(oai);

            // Install the Zones
            SmartThingsRepository.InstallDevices(this.Request.Host.Value);
            return View(oai);

        }
开发者ID:joejarvis64,项目名称:j64.AlarmServer,代码行数:64,代码来源:OAuthController.cs

示例8: HistoryAsync

     /// <summary>User Activity</summary>
     /// <param name="offset">Offset the list of returned results by this amount. Default is zero.</param>
     /// <param name="limit">Number of items to retrieve. Default is 5, maximum is 100.</param>
     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <returns>History information for the given user</returns>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task<Activities> HistoryAsync(int? offset, int? limit, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}?", BaseUrl, "history");
 
         if (offset != null)
             url_ += string.Format("offset={0}&", System.Uri.EscapeDataString(offset.Value.ToString()));
 
         if (limit != null)
             url_ += string.Format("limit={0}&", System.Uri.EscapeDataString(limit.Value.ToString()));
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			request_.Method = new System.Net.Http.HttpMethod("GET");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "200") 
 			{
 				var result_ = default(Activities); 
 				try
 				{
 					if (responseData_.Length > 0)
 						result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<Activities>(System.Text.Encoding.UTF8.GetString(responseData_, 0, responseData_.Length));                                
 					return result_; 
 				} 
 				catch (System.Exception exception) 
 				{
 					throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, exception);
 				}
 			}
 			else
 			{
 				var result_ = default(Error); 
 				try
 				{
 					if (responseData_.Length > 0)
 						result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<Error>(System.Text.Encoding.UTF8.GetString(responseData_, 0, responseData_.Length));
 
 				} 
 				catch (System.Exception exception_) 
 				{
 					throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, exception_);
 				}
 
 				throw new SwaggerException<Error>("Unexpected error", status_, responseData_, result_, null);
 			}
 		
 			return default(Activities);
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:62,代码来源:UberClient.cs

示例9: InstallDevices

        /// <summary>
        /// Install or Update Devices in the SmartThings App
        /// </summary>
        public static void InstallDevices(string hostString)
        {
            try
            {
                var alarm = AlarmSystemRepository.Get();
                if (string.IsNullOrEmpty(alarm.j64Server) || string.IsNullOrEmpty(alarm.j64Port))
                    Determinej64ServerAddress(hostString);

                OauthInfo authInfo = OauthRepository.Get();

                if (authInfo == null | authInfo.endpoints == null || authInfo.endpoints.Count == 0)
                {
                    MyLogger.LogError("OAuth endpoints have not been created. Cannot update smart things at this time");
                    return;
                }
                string url = authInfo.endpoints[0].uri + $"/installDevices";

                var client = new System.Net.Http.HttpClient();

                System.Net.Http.HttpRequestMessage msg = new System.Net.Http.HttpRequestMessage(System.Net.Http.HttpMethod.Post, url);
                msg.Headers.Add("Authorization", $"Bearer {authInfo.accessToken}");

                List<KeyValuePair<string, string>> parms = new List<KeyValuePair<string, string>>();
                parms.Add(new KeyValuePair<string, string>("j64Server", alarm.j64Server));
                parms.Add(new KeyValuePair<string, string>("j64Port", alarm.j64Port));
                parms.Add(new KeyValuePair<string, string>("j64UserName", "admin"));
                parms.Add(new KeyValuePair<string, string>("j64Password", "Admin_01"));
                msg.Content = new System.Net.Http.FormUrlEncodedContent(parms);
                var response = client.SendAsync(msg);
                response.Wait();

                if (response.Result.StatusCode != System.Net.HttpStatusCode.Created)
                {
                    MyLogger.LogError($"Error installing smart things devices.  StatusCode was {response.Result.StatusCode}");
                }
            }
            catch (Exception ex)
            {
                MyLogger.LogError($"Error installing smart things devices.  Exception was {MyLogger.ExMsg(ex)}");
            }
        }
开发者ID:joejarvis64,项目名称:j64.AlarmServer,代码行数:44,代码来源:SmartThingsRepository.cs

示例10: UpdateUserAsync

     /// <summary>Updated user</summary>
     /// <param name="username">name that need to be updated</param>
     /// <param name="body">Updated user object</param>
     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task UpdateUserAsync(string username, User body, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}", BaseUrl, "user/{username}");
 
         if (username == null)
             throw new System.ArgumentNullException("username");
         url_ = url_.Replace("{username}", System.Uri.EscapeDataString(username.ToString()));
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body));
 			content_.Headers.ContentType.MediaType = "application/json";
 			request_.Content = content_;
 			request_.Method = new System.Net.Http.HttpMethod("PUT");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "400") 
 			{
 				throw new SwaggerException("Invalid user supplied", status_, responseData_, null);
 			}
 			else
 			if (status_ == "404") 
 			{
 				throw new SwaggerException("User not found", status_, responseData_, null);
 			}
 			else
 			if (status_ != "200" && status_ != "204")
 				throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null);
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:42,代码来源:PetStoreClient.cs

示例11: GetUserByNameAsync

     /// <summary>Get user by user name</summary>
     /// <param name="username">The name that needs to be fetched. Use user1 for testing.</param>
     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <returns>successful operation</returns>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task<User> GetUserByNameAsync(string username, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}", BaseUrl, "user/{username}");
 
         if (username == null)
             throw new System.ArgumentNullException("username");
         url_ = url_.Replace("{username}", System.Uri.EscapeDataString(username.ToString()));
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			request_.Method = new System.Net.Http.HttpMethod("GET");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "200") 
 			{
 				var result_ = default(User); 
 				try
 				{
 					if (responseData_.Length > 0)
 						result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<User>(System.Text.Encoding.UTF8.GetString(responseData_, 0, responseData_.Length));                                
 					return result_; 
 				} 
 				catch (System.Exception exception) 
 				{
 					throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, exception);
 				}
 			}
 			else
 			if (status_ == "400") 
 			{
 				throw new SwaggerException("Invalid username supplied", status_, responseData_, null);
 			}
 			else
 			if (status_ == "404") 
 			{
 				throw new SwaggerException("User not found", status_, responseData_, null);
 			}
 			else
 			if (status_ != "200" && status_ != "204")
 				throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null);
 		
 			return default(User);
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:56,代码来源:PetStoreClient.cs

示例12: LogoutUserAsync

     /// <summary>Logs out current logged in user session</summary>
     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <returns>successful operation</returns>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task LogoutUserAsync(System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}", BaseUrl, "user/logout");
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			request_.Method = new System.Net.Http.HttpMethod("GET");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:22,代码来源:PetStoreClient.cs

示例13: CreateUsersWithListInputAsync

     /// <summary>Creates list of users with given input array</summary>
     /// <param name="body">List of user object</param>
     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <returns>successful operation</returns>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task CreateUsersWithListInputAsync(System.Collections.Generic.IEnumerable<User> body, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}", BaseUrl, "user/createWithList");
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body));
 			content_.Headers.ContentType.MediaType = "application/json";
 			request_.Content = content_;
 			request_.Method = new System.Net.Http.HttpMethod("POST");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:26,代码来源:PetStoreClient.cs

示例14: PlaceOrderAsync

     /// <summary>Place an order for a pet</summary>
     /// <param name="body">order placed for purchasing the pet</param>
     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <returns>successful operation</returns>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task<Order> PlaceOrderAsync(Order body, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}", BaseUrl, "store/order");
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			var content_ = new System.Net.Http.StringContent(Newtonsoft.Json.JsonConvert.SerializeObject(body));
 			content_.Headers.ContentType.MediaType = "application/json";
 			request_.Content = content_;
 			request_.Method = new System.Net.Http.HttpMethod("POST");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "200") 
 			{
 				var result_ = default(Order); 
 				try
 				{
 					if (responseData_.Length > 0)
 						result_ = Newtonsoft.Json.JsonConvert.DeserializeObject<Order>(System.Text.Encoding.UTF8.GetString(responseData_, 0, responseData_.Length));                                
 					return result_; 
 				} 
 				catch (System.Exception exception) 
 				{
 					throw new SwaggerException("Could not deserialize the response body.", status_, responseData_, exception);
 				}
 			}
 			else
 			if (status_ == "400") 
 			{
 				throw new SwaggerException("Invalid Order", status_, responseData_, null);
 			}
 			else
 			if (status_ != "200" && status_ != "204")
 				throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null);
 		
 			return default(Order);
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:50,代码来源:PetStoreClient.cs

示例15: DeletePetAsync

     /// <summary>Deletes a pet</summary>
     /// <param name="petId">Pet id to delete</param>
     /// <param name="cancellationToken">A cancellation token that can be used by other objects or threads to receive notice of cancellation.</param>
     /// <exception cref="SwaggerException">A server side error occurred.</exception>
     public async System.Threading.Tasks.Task DeletePetAsync(string api_key, int petId, System.Threading.CancellationToken cancellationToken)
     {
         var url_ = string.Format("{0}/{1}", BaseUrl, "pet/{petId}");
 
         if (petId == null)
             throw new System.ArgumentNullException("petId");
         url_ = url_.Replace("{petId}", System.Uri.EscapeDataString(petId.ToString()));
 
         using (var client_ = new System.Net.Http.HttpClient())
 		{
 			var request_ = new System.Net.Http.HttpRequestMessage();
 			PrepareRequest(client_, ref url_);
 			request_.Headers.TryAddWithoutValidation("api_key", api_key);
 			request_.Method = new System.Net.Http.HttpMethod("DELETE");
 			request_.RequestUri = new System.Uri(url_, System.UriKind.RelativeOrAbsolute);
 			var response_ = await client_.SendAsync(request_, System.Net.Http.HttpCompletionOption.ResponseContentRead, cancellationToken).ConfigureAwait(false);
 			ProcessResponse(client_, response_);
 
 			var responseData_ = await response_.Content.ReadAsByteArrayAsync().ConfigureAwait(false); 
 			var status_ = ((int)response_.StatusCode).ToString();
 
 			if (status_ == "400") 
 			{
 				throw new SwaggerException("Invalid ID supplied", status_, responseData_, null);
 			}
 			else
 			if (status_ == "404") 
 			{
 				throw new SwaggerException("Pet not found", status_, responseData_, null);
 			}
 			else
 			if (status_ != "200" && status_ != "204")
 				throw new SwaggerException("The HTTP status code of the response was not expected (" + (int)response_.StatusCode + ").", status_, responseData_, null);
 		}
 	}
开发者ID:NSwag,项目名称:NSwag,代码行数:39,代码来源:PetStoreClient.cs


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