public string Request(string url, string cmd, Crestron.SimplSharp.Net.Http.RequestType reqtype) { _request.Url.Parse(url); _request.RequestType = reqtype; if (cmd == null) { _request.ContentString = ""; } else { _request.ContentString = cmd; } _response = _client.Dispatch(_request); String jsontext = _response.ContentString; return jsontext; }
private HttpResult SendRequest(string url, RequestType requestType, string content, IEnumerable <KeyValuePair <string, string> > additionalHeaders) { var obj = httpClientPool.GetFromPool(); var client = obj.Value; try { if (client.ProcessBusy) { client.Abort(); } var httpRequest = new HttpClientRequest { RequestType = requestType, Encoding = Encoding.UTF8, KeepAlive = false, }; if (requestType != RequestType.Get && !string.IsNullOrEmpty(content)) { httpRequest.ContentSource = ContentSource.ContentString; httpRequest.ContentString = content; } if (additionalHeaders != null) { foreach (var item in additionalHeaders) { httpRequest.Header.AddHeader(new HttpHeader(item.Key, item.Value)); } } httpRequest.Url.Parse(url); HttpClientResponse httpResponse = client.Dispatch(httpRequest); return(new HttpResult(httpResponse.Code, httpResponse.ResponseUrl, httpResponse.ContentString)); } catch (Exception ex) { throw ex; } finally { httpClientPool.AddToPool(obj); } }