private static void CopyHeaders(Windows.Web.Http.Headers.HttpResponseHeaderCollection input, HttpResponseHeaders output) { foreach (var header in input) { output.Add(header.Key, header.Value); } }
public async Task<string> PostStringAsync(string link, string param) { try { System.Diagnostics.Debug.WriteLine(param); Uri uri = new Uri(link); HttpClient httpClient = new HttpClient(); HttpStringContent httpStringContent = new HttpStringContent(param, Windows.Storage.Streams.UnicodeEncoding.Utf8,"application/x-www-form-urlencoded"); //,Windows.Storage.Streams.UnicodeEncoding.Utf8 HttpResponseMessage response = await httpClient.PostAsync(uri, httpStringContent).AsTask(cts.Token); responseHeaders = response.Headers; System.Diagnostics.Debug.WriteLine(responseHeaders); string responseBody = await response.Content.ReadAsStringAsync().AsTask(cts.Token); return responseBody; } catch(Exception e) { return "Error:" + e.Message; } }
/// <summary> /// Copies headers from one <see cref="Windows.Web.Http.HttpResponseMessage"/> instance to another. /// </summary> /// <param name="source">The source <see cref="Windows.Web.Http.HttpResponseMessage"/> to copy from.</param> /// <param name="destination">The destination <see cref="Windows.Web.Http.HttpResponseMessage"/> to copy to.</param> public static void CopyHeadersTo(this Windows.Web.Http.Headers.HttpResponseHeaderCollection source, Windows.Web.Http.Headers.HttpResponseHeaderCollection destination) { if (source == null) { throw new ArgumentNullException(nameof(source)); } if (destination == null) { throw new ArgumentNullException(nameof(destination)); } foreach (var header in source) { if (destination.ContainsKey(header.Key)) { destination.Remove(header.Key); } destination.Add(header.Key, header.Value); } }