Fix for BigCharts Feed
This commit is contained in:
@@ -406,79 +406,106 @@ namespace MarketData.Integration
|
||||
}
|
||||
}
|
||||
|
||||
public static HttpNetResponse GetRequestNoEncodingV2(String strRequest,CookieCollection cookieCollection,Uri uri,WebProxy webProxy=null)
|
||||
/// <summary>
|
||||
/// This one is being used in the MarketWatch price fetch
|
||||
/// </summary>
|
||||
/// <param name="strRequest"></param>
|
||||
/// <param name="cookieCollection"></param>
|
||||
/// <param name="uri"></param>
|
||||
/// <param name="webProxy"></param>
|
||||
/// <returns></returns>
|
||||
public static HttpNetResponse GetRequestNoEncodingV2(String strRequest, CookieCollection cookieCollection, Uri uri, WebProxy webProxy = null)
|
||||
{
|
||||
HttpWebResponse webResponse=null;
|
||||
HttpWebResponse webResponse = null;
|
||||
try
|
||||
{
|
||||
ServicePointManager.Expect100Continue = true;
|
||||
MDTrace.WriteLine(LogLevel.VERBOSE,String.Format("GetRequestNoEncoding[ENTER]{0}",strRequest));
|
||||
ServicePointManager.Expect100Continue = true;
|
||||
MDTrace.WriteLine(LogLevel.VERBOSE, String.Format("GetRequestNoEncodingV2[ENTER]{0}", strRequest));
|
||||
int charCount = 0;
|
||||
byte[] buffer = new byte[8192];
|
||||
StringBuilder sb = new StringBuilder();
|
||||
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(strRequest));
|
||||
if(null!=webProxy)webRequest.Proxy=webProxy;
|
||||
if (null != webProxy) webRequest.Proxy = webProxy;
|
||||
webRequest.Timeout = REQUEST_TIMEOUT;
|
||||
webRequest.Accept = "text/html, text/csv";
|
||||
webRequest.ContentType="text/csv; charset=utf-8";
|
||||
webRequest.Headers.Add("Accept-Encoding: identity");
|
||||
webRequest.Headers.Add("Accept-Language: en-US");
|
||||
webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7";
|
||||
webRequest.Headers.Add("Accept-Encoding: gzip, deflate, br, zstd");
|
||||
webRequest.Headers.Add("Accept-Language: en-US,en;q=0.9");
|
||||
webRequest.UserAgent = "Mozilla/5.0 (X11; CrOS x86_64 14541.0.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/139.0.0.0 Safari/537.36";
|
||||
webRequest.Headers.Add("sec-fetch-dest", "document");
|
||||
webRequest.Headers.Add("sec-fetch-mode", "navigate");
|
||||
webRequest.Headers.Add("sec-fetch-site","none");
|
||||
webRequest.Headers.Add("sec-fetch-user","?1");
|
||||
webRequest.Headers.Add("upgrade-insecure-requests","1");
|
||||
webRequest.Headers.Add("priority","u=0, i");
|
||||
webRequest.Headers.Add("sec-fetch-dest", "document");
|
||||
webRequest.Headers.Add("sec-fetch-mode", "navigate");
|
||||
webRequest.Headers.Add("sec-fetch-site", "none");
|
||||
webRequest.Headers.Add("sec-fetch-user", "?1");
|
||||
webRequest.Headers.Add("upgrade-insecure-requests", "1");
|
||||
|
||||
webRequest.Headers.Add("priority", "u=0, i");
|
||||
webRequest.Headers.Add("sec-ch-device-memory", "8");
|
||||
|
||||
webRequest.Headers.Add("Referrer-Policy", "strict-origin-when-cross-origin");
|
||||
webRequest.AllowAutoRedirect = true;
|
||||
|
||||
// webRequest.KeepAlive = true;
|
||||
if (null != cookieCollection)
|
||||
{
|
||||
CookieContainer cookieContainer = new CookieContainer();
|
||||
foreach (Cookie cookie in cookieCollection)
|
||||
{
|
||||
cookieContainer.Add(uri,cookie);
|
||||
cookieContainer.Add(uri, cookie);
|
||||
}
|
||||
webRequest.CookieContainer = cookieContainer;
|
||||
}
|
||||
|
||||
try { webResponse = (HttpWebResponse)webRequest.GetResponse(); }
|
||||
catch (WebException webException)
|
||||
{
|
||||
if (IsMovedException(webException))
|
||||
{
|
||||
webRequest = Redirect(webRequest, webException);
|
||||
webResponse = (HttpWebResponse)webRequest.GetResponse();
|
||||
}
|
||||
else throw;
|
||||
}
|
||||
Stream responseStream = webResponse.GetResponseStream();
|
||||
while (true)
|
||||
catch (WebException webException)
|
||||
{
|
||||
charCount = responseStream.Read(buffer, 0, buffer.Length);
|
||||
if (0 >= charCount) break;
|
||||
sb.Append(Encoding.ASCII.GetString(buffer, 0, charCount));
|
||||
if (IsMovedException(webException))
|
||||
{
|
||||
webRequest = Redirect(webRequest, webException);
|
||||
webResponse = (HttpWebResponse)webRequest.GetResponse();
|
||||
}
|
||||
else throw;
|
||||
}
|
||||
return new HttpNetResponse(sb.ToString(),strRequest,webResponse,true);
|
||||
Stream responseStream = webResponse.GetResponseStream();
|
||||
|
||||
if (webResponse.ContentEncoding.ToLower().Contains("gzip"))
|
||||
{
|
||||
responseStream = new GZipStream(responseStream, CompressionMode.Decompress);
|
||||
StreamReader reader = new StreamReader(responseStream, Encoding.Default);
|
||||
sb.Append(reader.ReadToEnd());
|
||||
reader.Close();
|
||||
}
|
||||
else if (webResponse.ContentEncoding.ToLower().Contains("deflate"))
|
||||
{
|
||||
responseStream = new DeflateStream(responseStream, CompressionMode.Decompress);
|
||||
StreamReader reader = new StreamReader(responseStream, Encoding.Default);
|
||||
sb.Append(reader.ReadToEnd());
|
||||
reader.Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
while (true)
|
||||
{
|
||||
charCount = responseStream.Read(buffer, 0, buffer.Length);
|
||||
if (0 == charCount) break;
|
||||
sb.Append(Encoding.ASCII.GetString(buffer, 0, charCount));
|
||||
}
|
||||
}
|
||||
return new HttpNetResponse(sb.ToString(), strRequest, webResponse, true);
|
||||
}
|
||||
catch (WebException webException)
|
||||
{
|
||||
return new HttpNetResponse((HttpWebResponse)webException.Response,strRequest,false,webException.Message);
|
||||
return new HttpNetResponse((HttpWebResponse)webException.Response, strRequest, false, webException.Message);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
return new HttpNetResponse(webResponse,strRequest,false,exception.Message);
|
||||
return new HttpNetResponse(webResponse, strRequest, false, exception.Message);
|
||||
}
|
||||
finally
|
||||
{
|
||||
if(null!=webResponse)
|
||||
if (null != webResponse)
|
||||
{
|
||||
webResponse.Close();
|
||||
webResponse.Dispose();
|
||||
}
|
||||
MDTrace.WriteLine(LogLevel.VERBOSE,"GetRequestNoEncoding[LEAVE]");
|
||||
MDTrace.WriteLine(LogLevel.VERBOSE, "GetRequestNoEncoding[LEAVE]");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user