public WebData() { RequestInfo = new WebDataRequestInfo(); ResponseInfo = new WebDataResponseInfo(); //ResponseData = new MemoryStream(); _requestProtocol = InternetProtocols.HTTP; // getting plugin availablity state _isPluginAvailable = Plugins.IsPluginAvailable(PluginHosts.IPluginWebData); }
public WebData() { RequestInfo = new WebDataRequestInfo(); ResponseInfo = new WebDataResponseInfo(); //ResponseData = new MemoryStream(); _requestProtocol = InternetProtocols.HTTP; try { // getting plugin availablity state _isPluginAvailable = Plugins.IsPluginAvailable(PluginHosts.IPluginWebData); } catch { } }
/// <summary> /// Initializes a web request /// </summary> protected virtual void InitializeWebRequest(WebRequest webRequest) { // Detecting requested url protocol _requestProtocol = DetectWebRequestProtocol(webRequest); if (_requestProtocol != InternetProtocols.FTP) { try { // This method may cause mono to fail to load, "Need EnvironmentPermission implementation first" // Set the Credentials webRequest.Credentials = CredentialCache.DefaultCredentials; } catch { // Just simple Mono exception } // ADDED again in v3.7:: Set request content type // Bug fixed v4.8, ftp does not support this webRequest.ContentType = RequestInfo.ContentType; } // Timeout is the number of milliseconds that a subsequent // synchronous request made with the GetResponse method waits // for a response, and the GetRequestStream method waits for a stream. if (RequestInfo.RequesterType == RequesterType.Download) { webRequest.Timeout = Configurations.WebData.Downloader_Timeout; } else { webRequest.Timeout = Configurations.WebData.RequestTimeout; } // If server has configured to pass through a proxy //if (Configurations.NetProxy.WebProxyEnabled) //{ // Use configured settings webRequest.Proxy = Configurations.NetProxy.GenerateWebProxy(); //} // add custom headers to request if (RequestInfo.CustomHeaders != null) { ApplyCustomHeaders(webRequest); } // ASProxy signature in request header if (Configurations.WebData.SendSignature) { webRequest.Headers.Add("X-Powered-By", Consts.BackEndConenction.ASProxyAgentVersion); webRequest.Headers.Add("X-Working-With", Consts.BackEndConenction.ASProxyAgentVersion); } // request credentials if (RequestInfo.IsCertificated) { // ADDED Since v5 webRequest.Credentials = RequestInfo.GetCertification(); } else if (Systems.CredentialCache.IsCertificated(RequestInfo.RequestUrl)) { // ADDED Since v4.1 webRequest.Credentials = Systems.CredentialCache.GetNetworkCertification(RequestInfo.RequestUrl); } switch (_requestProtocol) { case InternetProtocols.HTTP: HttpWebRequest httpRequest = ((HttpWebRequest)_webRequest); // force to close connection! httpRequest.KeepAlive = true; // The ReadWriteTimeout property controls the time-out for the Read method, // which is used to read the stream returned by the GetResponseStream method, // and for the Write method, which is used to write to the stream returned by // the GetRequestStream method. // Timeout is in milliseconds if (RequestInfo.RequesterType == RequesterType.Download) { httpRequest.ReadWriteTimeout = Configurations.WebData.Downloader_ReadWriteTimeOut; } else { httpRequest.ReadWriteTimeout = Configurations.WebData.RequestReadWriteTimeOut; } // Enabling cookies if (RequestInfo.AcceptCookies) { httpRequest.CookieContainer = new CookieContainer(); httpRequest.CookieContainer.MaxCookieSize = MaxCookieSize; try { // TODO: Implement CookieManager if (RequestInfo.Cookies == null || RequestInfo.Cookies.Count == 0) { Systems.CookieManager.AddCookiesToRequest(_webRequest); } else { Systems.CookieManager.AddCookiesToRequest(_webRequest, RequestInfo.Cookies); } } catch (Exception ex) { if (Systems.LogSystem.ErrorLogEnabled) { Systems.LogSystem.LogError(ex, _webRequest.RequestUri.ToString()); } LastErrorMessage = ex.Message; LastException = ex; LastStatus = LastStatus.ContinueWithError; } } // Does not allow auto rediraction. // BUG: In second redirection cookies does not saved // BUG-FIXED in V4.3 httpRequest.AllowAutoRedirect = false; // Request referrer switch (RequestInfo.ReferrerUsage) { case ReferrerType.None: httpRequest.Referer = String.Empty; break; case ReferrerType.ASProxySite: httpRequest.Referer = Consts.BackEndConenction.ASProxyProjectUrl; break; case ReferrerType.RequesterAsReferrer: httpRequest.Referer = _webRequest.RequestUri.ToString(); break; case ReferrerType.Referrer: httpRequest.Referer = RequestInfo.Referrer; break; } // web method if (!string.IsNullOrEmpty(RequestInfo.RequestMethod)) { httpRequest.Method = RequestInfo.RequestMethod; } // user agent if (!string.IsNullOrEmpty(RequestInfo.UserAgent)) { httpRequest.UserAgent = RequestInfo.UserAgent; } break; case InternetProtocols.FTP: FtpWebRequest ftpReq = ((FtpWebRequest)_webRequest); // For now only downloading is supported ftpReq.Method = WebRequestMethods.Ftp.DownloadFile; break; case InternetProtocols.File: // Still nothing break; case InternetProtocols.Other: // Still nothing break; default: break; } }
/// <summary> /// Initializes a web request /// </summary> protected virtual void InitializeWebRequest(WebRequest webRequest) { // Detecting requested url protocol _requestProtocol = DetectWebRequestProtocol(webRequest); if (_requestProtocol != InternetProtocols.FTP) { try { // This method may cause mono to fail to load, "Need EnvironmentPermission implementation first" // Set the Credentials webRequest.Credentials = CredentialCache.DefaultCredentials; } catch { // Just simple Mono exception } // ADDED again in v3.7:: Set request content type // Bug fixed v4.8, ftp does not support this webRequest.ContentType = RequestInfo.ContentType; } // Timeout is the number of milliseconds that a subsequent // synchronous request made with the GetResponse method waits // for a response, and the GetRequestStream method waits for a stream. if (RequestInfo.RequesterType == RequesterType.Download) webRequest.Timeout = Configurations.WebData.Downloader_Timeout; else webRequest.Timeout = Configurations.WebData.RequestTimeout; // If server has configured to pass through a proxy if (Configurations.NetProxy.WebProxyEnabled) { // Use configured settings webRequest.Proxy = Configurations.NetProxy.GenerateWebProxy(); } // add custom headers to request if (RequestInfo.CustomHeaders != null) ApplyCustomHeaders(webRequest); // ASProxy signature in request header if (Configurations.WebData.SendSignature) { webRequest.Headers.Add("X-Powered-By", Consts.BackEndConenction.ASProxyAgentVersion); webRequest.Headers.Add("X-Working-With", Consts.BackEndConenction.ASProxyAgentVersion); } // request credentials if (RequestInfo.IsCertificated) { // ADDED Since v5 webRequest.Credentials = RequestInfo.GetCertification(); } else if (Systems.CredentialCache.IsCertificated(RequestInfo.RequestUrl)) { // ADDED Since v4.1 webRequest.Credentials = Systems.CredentialCache.GetNetworkCertification(RequestInfo.RequestUrl); } switch (_requestProtocol) { case InternetProtocols.HTTP: HttpWebRequest httpRequest = ((HttpWebRequest)_webRequest); // The ReadWriteTimeout property controls the time-out for the Read method, // which is used to read the stream returned by the GetResponseStream method, // and for the Write method, which is used to write to the stream returned by // the GetRequestStream method. // Timeout is in milliseconds if (RequestInfo.RequesterType == RequesterType.Download) httpRequest.ReadWriteTimeout = Configurations.WebData.Downloader_ReadWriteTimeOut; else httpRequest.ReadWriteTimeout = Configurations.WebData.RequestReadWriteTimeOut; // Enabling cookies if (RequestInfo.AcceptCookies) { httpRequest.CookieContainer = new CookieContainer(); httpRequest.CookieContainer.MaxCookieSize = MaxCookieSize; try { // TODO: Implement CookieManager if (RequestInfo.Cookies == null || RequestInfo.Cookies.Count == 0) Systems.CookieManager.AddCookiesToRequest(_webRequest); else Systems.CookieManager.AddCookiesToRequest(_webRequest, RequestInfo.Cookies); } catch (Exception ex) { if (Systems.LogSystem.ErrorLogEnabled) Systems.LogSystem.LogError(ex, _webRequest.RequestUri.ToString()); LastErrorMessage = ex.Message; LastException = ex; LastStatus = LastStatus.ContinueWithError; } } // Does not allow auto rediraction. // BUG: In second redirection cookies does not saved // BUG-FIXED in V4.3 httpRequest.AllowAutoRedirect = false; // Request referrer switch (RequestInfo.ReferrerUsage) { case ReferrerType.None: httpRequest.Referer = String.Empty; break; case ReferrerType.ASProxySite: httpRequest.Referer = Consts.BackEndConenction.ASProxyProjectUrl; break; case ReferrerType.RequesterAsReferrer: httpRequest.Referer = _webRequest.RequestUri.ToString(); break; case ReferrerType.Referrer: httpRequest.Referer = RequestInfo.Referrer; break; } // web method if (!string.IsNullOrEmpty(RequestInfo.RequestMethod)) httpRequest.Method = RequestInfo.RequestMethod; // user agent if (!string.IsNullOrEmpty(RequestInfo.UserAgent)) httpRequest.UserAgent = RequestInfo.UserAgent; break; case InternetProtocols.FTP: FtpWebRequest ftpReq = ((FtpWebRequest)_webRequest); // For now only downloading is supported ftpReq.Method = WebRequestMethods.Ftp.DownloadFile; break; case InternetProtocols.File: // Still nothing break; case InternetProtocols.Other: // Still nothing break; default: break; } }