Torna al Thread

Function GetHtmlPageSource(ByVal url As String, Optional ByVal username As String = Nothing, Optional ByVal password As String = Nothing) As String Dim st As System.IO.Stream Dim sr As System.IO.StreamReader Try ' invia una Web request Dim req As System.Net.WebRequest = System.Net.WebRequest.Create(url) ' se sono specificati username/password usa le credenziali If Not username Is Nothing AndAlso Not password Is Nothing Then req.Credentials = New System.Net.NetworkCredential(username, password) End If ' ricava la risposta e legge lo stream coi risultati Dim resp As System.Net.WebResponse = req.GetResponse st = resp.GetResponseStream sr = New System.IO.StreamReader(st) Return sr.ReadToEnd Catch ex As Exception Return "" Finally sr.Close() st.Close() End Try End Function
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5