Add an additional method to the SeekingAlpha news feed.

This commit is contained in:
2025-02-11 19:20:15 -05:00
parent 8090a5e093
commit 76a4768d81
2 changed files with 151 additions and 2 deletions

View File

@@ -1116,6 +1116,63 @@ namespace MarketData.Integration
}
}
public static HttpNetResponse GetRequestNoEncodingV5D(String strRequest,String host,int webRequestTimeoutMS,WebProxy webProxy=null,bool useRandomUserAgent=false,CookieCollection cookieCollection=null)
{
HttpWebResponse webResponse = null;
try
{
MDTrace.WriteLine(LogLevel.VERBOSE, String.Format("GetRequestNoEncodingV5C[ENTER]{0}", strRequest));
byte[] buffer = new byte[8192];
StringBuilder sb = new StringBuilder();
bool expect100Condition = ServicePointManager.Expect100Continue;
SecurityProtocolType securityProtocolType = ServicePointManager.SecurityProtocol;
ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(new Uri(strRequest));
if(null!=webProxy)webRequest.Proxy=webProxy;
webRequest.Timeout = webRequestTimeoutMS;
webRequest.KeepAlive=true;
webRequest.Headers.Add("Priority: u=0, i");
webRequest.Headers.Add("Accept-Language: en-US,en;q=0.5");
webRequest.Headers.Add("Accept-Encoding: gzip, deflate, br, zstd");
webRequest.Host = host;
webRequest.Headers.Add("Sec-GPC: 1");
webRequest.Headers.Add("Sec-Fetch-Dest: document");
webRequest.Headers.Add("Sec-Fetch-Mode: navigate");
webRequest.Headers.Add("Sec-Fetch-Site: crosssite");
webRequest.Headers.Add("Sec-Fetch-User: ?1");
webRequest.Headers.Add("DNT: 1");
webRequest.Headers.Add("Upgrade-Insecure-Requests: 1");
webRequest.Headers.Add("TE: trailers");
webRequest.Headers.Add("If-None-Match: "+"W/\"e76e3614af0e341af5df8daa8b855a4e\"");
webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
if (useRandomUserAgent) webRequest.UserAgent = UserAgent.GetInstance().GetUserAgent();
else webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36";
webRequest.CookieContainer = new CookieContainer();
if(null!=cookieCollection)webRequest.CookieContainer.Add(cookieCollection);
webResponse = (HttpWebResponse)webRequest.GetResponse();
HttpNetResponse httpNetResponse = ProcessWebResponse(strRequest, webResponse);
httpNetResponse.CookieCollection = new CookieCollection();
httpNetResponse.CookieCollection.Add(webResponse.Cookies);
webResponse.Close();
ServicePointManager.Expect100Continue = expect100Condition;
ServicePointManager.SecurityProtocol = securityProtocolType;
return httpNetResponse;
}
catch (WebException webException)
{
return new HttpNetResponse((HttpWebResponse)webException.Response, strRequest, false, webException.Message);
}
catch (Exception exception)
{
return new HttpNetResponse(webResponse, strRequest, false, exception.Message);
}
finally
{
MDTrace.WriteLine(LogLevel.VERBOSE, "GetRequestNoEncodingV5C[LEAVE]");
}
}
private static HttpNetResponse ProcessWebResponse(String strRequest,HttpWebResponse webResponse)
{
try