public async Task SaveToDoItemAsync(ToDoItem item, bool isNewItem = false) { try { string jsonItem = JsonConvert.SerializeObject(item); StringContent content = new StringContent(jsonItem, Encoding.UTF8, JsonMediaType); string requestUri = string.Format(Constants.ToDoApiUri, string.Empty); HttpResponseMessage response = null; if (isNewItem) { response = await _client.PostAsync(requestUri, content); } else { response = await _client.PutAsync(requestUri, content); } if (response.IsSuccessStatusCode) { Debug.WriteLine("TodoItem successfully saved."); } } catch (Exception ex) { Debug.WriteLine($"Error occurred calling ToDoApi: {ex.Message}"); } }
private void Put(Job job) { _log.Debug($"[JobId={job.JobId}] [MessageText=Sending HTTP PUT request to {job.CallbackUrl}.]"); var content = new StringContent(job.Payload, Encoding.UTF8, job.ContentType); var request = _client.PutAsync(job.CallbackUrl, content).Result; request.EnsureSuccessStatusCode(); }
public TResponse PutJson <TRequest, TResponse>(TRequest request, string path) { var stringContent = new StringContent( JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); var uri = BuildHttpClientUri( GatewayHost, $"{GatewayApiPath}/{path}", GatewayPort); var response = Send <TResponse>(async() => await _client .PutAsync(uri, stringContent) .ConfigureAwait(false)); return(response); }
public System.Threading.Tasks.Task UpdateSalesAsync(IEnumerable <SaleDto> salesDto) { if (salesDto == null) { throw new ArgumentNullException(nameof(salesDto)); } string updateSalesUrl = configuration[EndPoints.Api.UpdateSales]; return(httpClient.PutAsync(updateSalesUrl, salesDto)); }
public async Task UpdateImposterAsync(Imposter imposter, CancellationToken cancellationToken = default) { var json = JsonConvert.SerializeObject(imposter); using ( var response = await _httpClient.PutAsync( $"{ImpostersResource}/{imposter.Port}/stubs", new StringContent(json), cancellationToken ).ConfigureAwait(false)) { await HandleResponse(response, HttpStatusCode.OK, $"Failed to replace stubs for the imposter with port {imposter.Port}.", (message) => new ImposterNotFoundException(message)).ConfigureAwait(false); } }
public async Task <bool> PutNewMarketingContactAsync(PutNewMarketingContactRequest request, CancellationToken cancellationToken) { string path = $"api/PutNewMarketingContact"; var jsonContent = new StringContent(JsonConvert.SerializeObject(request), Encoding.UTF8, "application/json"); using (HttpResponseMessage response = await _httpClientWrapper.PutAsync(HttpClientConfigName.CommunicationService, path, jsonContent, cancellationToken).ConfigureAwait(false)) { string jsonResponse = await response.Content.ReadAsStringAsync(); var putNewMarketingContactResponse = JsonConvert.DeserializeObject <ResponseWrapper <bool, CommunicationServiceErrorCode> >(jsonResponse); if (putNewMarketingContactResponse.HasContent && putNewMarketingContactResponse.IsSuccessful) { return(putNewMarketingContactResponse.Content); } return(false); } }
public async Task <RuleApiModel> UpsertAsync(string id, RuleApiModel rule) { string requestUri = $"{uri}/{id}"; return(await httpClient.PutAsync <RuleApiModel>(requestUri, rule, "monitoring rules")); }