private HttpsResult SendRequest(string url, RequestType requestType, IEnumerable <KeyValuePair <string, string> > additionalHeaders, string value) { using (_requestLock.AquireLock()) { HttpsClientRequest httpRequest = CreateDefaultClientRequest(url, requestType); if (additionalHeaders != null) { foreach (var item in additionalHeaders) { httpRequest.Header.AddHeader(new HttpsHeader(item.Key, item.Value)); } } if (!string.IsNullOrEmpty(value)) { httpRequest.ContentString = value; } try { HttpsClientResponse httpResponse = _httpsClient.Value.Dispatch(httpRequest); return(new HttpsResult(httpResponse.Code, httpResponse.ResponseUrl, httpResponse.ContentString)); } catch (HttpsException ex) { Debug.LogException(GetType(), ex); } return(null); } }
internal static string HttpsJsonRequest(string uri, Crestron.SimplSharp.Net.Https.RequestType requestType, string key, string msg, string contentType) { HttpsClient client = new HttpsClient(); client.HostVerification = false; client.PeerVerification = false; try { HttpsClientRequest aRequest = new HttpsClientRequest(); //HttpsClientRequest aRequest = new HttpsClientRequest(); string aUrl = uri; aRequest.Url.Parse(aUrl); aRequest.Encoding = Encoding.UTF8; aRequest.RequestType = requestType; aRequest.Header.ContentType = contentType; aRequest.ContentString = msg; aRequest.Header.SetHeaderValue("Authorization", key); HttpsClientResponse myResponse = client.Dispatch(aRequest); return(myResponse.ContentString); } catch (Exception ex) { LogException(@"SyncProMethods \ GenericHttpsRequest", ex); return(null); } }
private static HttpsClientRequest CreateDefaultClientRequest(string url, RequestType requestType) { var httpRequest = new HttpsClientRequest { Encoding = Encoding.UTF8, RequestType = requestType, Url = new UrlParser(url) }; return(httpRequest); }
private HttpsResult SendRequest(string url, RequestType requestType, IEnumerable <KeyValuePair <string, string> > additionalHeaders, string content) { var obj = _httpsClientPool.GetFromPool(); var client = obj.Value; try { Debug.WriteInfo("Making API GET request to endpoint: {0}", url); if (client.ProcessBusy) { client.Abort(); } var httpsRequest = new HttpsClientRequest { RequestType = requestType, Encoding = Encoding.UTF8, KeepAlive = false, }; if (requestType != RequestType.Get && !string.IsNullOrEmpty(content)) { httpsRequest.ContentSource = ContentSource.ContentString; httpsRequest.ContentString = content; } if (additionalHeaders != null) { foreach (var item in additionalHeaders) { httpsRequest.Header.AddHeader(new HttpsHeader(item.Key, item.Value)); } } httpsRequest.Url.Parse(url); HttpsClientResponse httpResponse = client.Dispatch(httpsRequest); return(new HttpsResult(httpResponse.Code, httpResponse.ResponseUrl, httpResponse.ContentString)); } catch (Exception ex) { Debug.WriteException(ex); } finally { _httpsClientPool.AddToPool(obj); } return(null); }