private HttpWebRequest GetAuthRequest(string url, string method, VmAuthorizeCredentials credentials) { if (!(WebRequest.Create(url) is HttpWebRequest webRequest)) { throw new Exception("Не могу открыть URL"); } if (!string.IsNullOrEmpty(_proxyDomain)) { var webProxy = new WebProxy(_proxyDomain, _proxyPort) { BypassProxyOnLocal = true }; webRequest.Proxy = webProxy; } webRequest.KeepAlive = true; webRequest.Method = method; webRequest.ContentType = "application/json; charset=utf-8"; webRequest.Accept = "application/json"; //webRequest.Credentials = CredentialCache.DefaultCredentials; string encoded = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(credentials.Login + ":" + credentials.Password)); webRequest.Headers.Add("Authorization", "Basic " + encoded); ServicePointManager.ServerCertificateValidationCallback = AcceptAllCertifications; return(webRequest); }
public async Task <T> AuthorizeGet <T>(string url, VmAuthorizeCredentials credentials) { var request = GetAuthRequest(url, WebRequestMethods.Http.Get, credentials); return(await GetGetResponse <T>(request)); }
public T WebApiAuthorizeRequestGet <T>(string url, VmAuthorizeCredentials credentials) { return(AuthorizeGet <T>(url, credentials).GetAwaiter().GetResult()); }
public string Get(VmAuthorizeCredentials credentials) { var session = _helper.WebApiAuthorizeRequestGet <string>(_smApiConfigModel.ApiAddress, credentials); return(session); }