Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Funzione per leggere una pagina web, tiene in considerazione i protocolli di sicurezza
/// <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
You can’t perform that action at this time.