public async void HttpPostRequest(String URL, String data) { System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@ post request (arguments)=>" + URL + data); HttpStringContent stringContent = new HttpStringContent(data, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json"); HttpClient client = new HttpClient(); System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@ post request (stringContent)=> " + stringContent); HttpResponseMessage response = await client.PostAsync(new Uri(URL), stringContent); this._statusCode = response.StatusCode; this._response = await response.Content.ReadAsStringAsync(); System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@ post request (response)=>" + this._response); if (this._statusCode == HttpStatusCode.Ok || this._statusCode == HttpStatusCode.NoContent) { value = true; } else { HandleErrorHttp err = new HandleErrorHttp(); err.popError(this._statusCode, this._response); value = false; } OnRequestFinished(EventArgs.Empty); }
public async void HttpPutRequestUpload(String URL, byte[] data, String contentType) { Stream stream = new MemoryStream(data); HttpStreamContent streamContent = new HttpStreamContent(stream.AsInputStream()); streamContent.Headers.TryAppendWithoutValidation("Content-Type", contentType); Uri resourceAddress = null; Uri.TryCreate(URL.Trim(), UriKind.Absolute, out resourceAddress); System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@ putImage request (address)=>" + resourceAddress); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, resourceAddress); request.Content = streamContent; HttpClient httpClient = new HttpClient(); HttpResponseMessage response = await httpClient.SendRequestAsync(request); this._statusCode = response.StatusCode; this._response = await response.Content.ReadAsStringAsync(); System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@ putImage request (response)=>" + response); if (this._statusCode == HttpStatusCode.Ok || this._statusCode == HttpStatusCode.NoContent) { value = true; } else { HandleErrorHttp err = new HandleErrorHttp(); err.popError(this._statusCode, this._response); value = false; } OnRequestFinished(EventArgs.Empty); }
public async void HttpGetRequest(String URL) { System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@ get request (arguments)=>" + URL); HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(new Uri(URL)); this._statusCode = response.StatusCode; this._response = await response.Content.ReadAsStringAsync(); System.Diagnostics.Debug.WriteLine("@@@@@@@@@@@@@@@ get request (response)=>" + this._response); if (this._statusCode == HttpStatusCode.Ok || this._statusCode == HttpStatusCode.NoContent) { value = true; } else { HandleErrorHttp err = new HandleErrorHttp(); err.popError(this._statusCode, this._response); value = false; } OnRequestFinished(EventArgs.Empty); }