HttpWebRequest buildRequest(string method, string name, CookieContainer cookies) { GXLogging.Debug(log, String.Format("Start HTTPClient buildRequest: requestUrl:{0} method:{1} name:{2}", _url, method, name)); int BytesRead; Byte[] Buffer = new Byte[1024]; string requestUrl = GetRequestURL(name); HttpWebRequest req = (HttpWebRequest)WebRequest.Create(requestUrl); if (GXUtil.CompressResponse()) { req.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate; } req.Credentials = getCredentialCache(req.RequestUri, _authCollection); req.CookieContainer = cookies; foreach (X509Certificate2 cert in _certificateCollection) { req.ClientCertificates.Add(cert); } req.Method = method.Trim(); req.Timeout = _timeout; setHttpVersion(req); WebProxy proxy = getProxy(_proxyHost, _proxyPort, _authProxyCollection); if (proxy != null) { req.Proxy = proxy; } setHeaders(req); if (method.ToUpper() != "GET") { #if !NETCORE using (Stream reqStream = req.GetRequestStream()) #else using (Stream reqStream = req.GetRequestStreamAsync().GetAwaiter().GetResult()) #endif { sendVariables(reqStream); SendStream.Seek(0, SeekOrigin.Begin); BytesRead = SendStream.Read(Buffer, 0, 1024); GXLogging.Debug(log, "Start SendStream.Read: BytesRead " + BytesRead); while (BytesRead > 0) { GXLogging.Debug(log, "reqStream.Write: Buffer.length " + Buffer.Length + ",'" + Encoding.UTF8.GetString(Buffer, 0, Buffer.Length) + "'"); reqStream.Write(Buffer, 0, BytesRead); BytesRead = SendStream.Read(Buffer, 0, 1024); } EndMultipartBoundary(reqStream); } } return(req); }
public GxRestService() { context = GxContext.CreateDefaultInstance(); wcfContext = WebOperationContext.Current; httpContext = HttpContext.Current; if (GXUtil.CompressResponse()) { GXUtil.SetGZip(httpContext); } }