public async Task <NetResponse> ExecuteAsync(NetRequest netRequest) { using (var request = new HttpRequestMessage()) { request.Method = new HttpMethod(Enum.GetName(typeof(HttpMethodOptions), netRequest.Method)); if (!string.IsNullOrEmpty(netRequest.Resource)) { request.RequestUri = new Uri(netRequest.Resource); } PrepareRequest(netRequest, request); return(await _httpService.GetResponseAsync(request)); } }
private void AppendCookies(NetRequest netRequest, HttpRequestMessage request) { var items = netRequest.Parameters.Where(m => m.ParamsOptions == ParameterOptions.Cookie); if (items == null || !items.Any()) { return; } var sCookie = string.Join(";", items.Select(m => m.ToString())); if (request.Headers.TryGetValues(HttpR.CookieKey, out var values)) { var cookieValue = values.First().Trim(';'); request.Headers.Remove(HttpR.CookieKey); request.Headers.Add(HttpR.CookieKey, string.Format("{0}{1}{2}", cookieValue, string.IsNullOrEmpty(cookieValue) ? "" : ";", sCookie)); } else { request.Headers.Add(HttpR.CookieKey, sCookie); } }