public static HttpClient Create(HttpClient _client, HClientCookie _clientCookie, HClientHeader _clientHeader) { HttpClient client = _client; client.DefaultRequestHeaders.Clear(); if (_clientCookie != null && _clientCookie.CookieDictionary != null) { foreach (var cookie in _clientCookie.CookieDictionary) { client.DefaultRequestHeaders.TryAddWithoutValidation("Cookie", $"{cookie.Key}={cookie.Value}"); } } if (_clientHeader != null) { client.DefaultRequestHeaders.TryAddWithoutValidation("Accept", _clientHeader.Accept); client.DefaultRequestHeaders.TryAddWithoutValidation("Referer", _clientHeader.Referer); client.DefaultRequestHeaders.TryAddWithoutValidation("UserAgent", _clientHeader.UserAgent); } if (_clientHeader != null && _clientHeader.headersKeyValuePairs != null) { foreach (var header in _clientHeader.headersKeyValuePairs) { client.DefaultRequestHeaders.TryAddWithoutValidation(header.Key, header.Value); } } return(client); }
private (HttpClient, MultipartFormDataContent) Create(HttpClient _client, HClientCookie _clientCookie, HClientHeader _clientHeader, HMultipart multipart) { HttpClient client = null; MultipartFormDataContent content = null; client = HClientService.Create(_client, _clientCookie, _clientHeader); content = HContentService.Create(multipart); return(client, content); }
private (HttpClient, HttpContent) Create(HttpClient _client, HClientCookie _clientCookie, HClientHeader _clientHeader, string _json = null) { HttpClient client = null; HttpContent hContent = null; client = HClientService.Create(_client, _clientCookie, _clientHeader); if (_json != null) { hContent = HContentService.Create(_json); } else { hContent = HContentService.Create(_clientHeader); } return(client, hContent); }
public async Task <HClientImgResponse> GetImage(string _requestUrl, HClientCookie _clientCookie = null, HClientHeader _clientHeader = null) { try { var instance = Create(client, _clientCookie, _clientHeader); client = instance.Item1; var resultMessage = await client.GetAsync(_requestUrl); hImgResponse = new HClientImgResponse(resultMessage); } catch (Exception ex) { hImgResponse = null; throw new Exception(ex.Message); } return(hImgResponse); }
public async Task <HClientResponse> Post(string _requestUrl, HClientCookie _clientCookie = null, HClientHeader _clientHeader = null, HMultipart multipart = null) { try { var instance = Create(client, _clientCookie, _clientHeader, multipart); client = instance.Item1; var content = instance.Item2; var resultMessage = await client.PostAsync(_requestUrl, content); hResponse = new HClientResponse(resultMessage); } catch (Exception ex) { hResponse = null; throw new Exception(ex.Message); } return(hResponse); }