Created
July 17, 2018 15:50
-
-
Save cTraderGURU/7a74b5c1a1efaa32b0df803a3be613a5 to your computer and use it in GitHub Desktop.
Funzione per leggere una pagina web, tiene in considerazione i protocolli di sicurezza
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <summary> | |
/// Funzione per la richiesta di pagine web. | |
/// Tiene in considerazione i protocolli di sicurezza e la cache. | |
/// </summary> | |
/// <returns> | |
/// Restituisce il source della pagina | |
/// </returns> | |
/// <example> | |
/// <code> | |
/// string homepage = _getHTMLSourceFromEndPoint( 'https://ctrader.guru/' ); | |
/// </code> | |
/// </example> | |
/// <param name="myEndPoint">L'indirizzo della pagina per la richiesta ( GET )</param> | |
string _getHTMLSourceFromEndPoint(string myEndPoint) | |
{ | |
myEndPoint = myEndPoint.Trim(); | |
myEndPoint = (myEndPoint.IndexOf("?") > -1) ? string.Format("{0}&t={1}", myEndPoint, DateTime.Now.ToString("yyyyMMddHHmmssffff")) : string.Format("{0}?t={1}", myEndPoint, DateTime.Now.ToString("yyyyMMddHHmmssffff")); | |
string responseInString = ""; | |
// --> Effettua la richiesta HTTP | |
// --> Regex urlRegEx = new System.Text.RegularExpressions.Regex("https://ctrader\\.guru/.*"); | |
WebPermission p = new System.Net.WebPermission(NetworkAccess.Connect, myEndPoint); | |
p.Assert(); | |
ServicePointManager.SecurityProtocol = (SecurityProtocolType)192 | (SecurityProtocolType)768 | (SecurityProtocolType)3072; | |
using (var wb = new WebClient()) | |
{ | |
wb.Headers.Add("User-Agent", "cTrader GURU"); | |
wb.Headers.Add("Accept", "*/*"); | |
wb.Headers.Add("Accept-Language", "en-gb,en;q=0.5"); | |
wb.Headers.Add("Accept-Charset", "utf-8;q=0.7,*;q=0.7"); | |
wb.Encoding = Encoding.UTF8; | |
responseInString = wb.DownloadString(myEndPoint); | |
// --> responseInString = Encoding.UTF8.GetString(wb.DownloadData(myEndPoint)); | |
} | |
return responseInString; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment