Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Getting files through http
Message
From
31/05/2006 21:28:52
 
 
To
31/05/2006 21:04:51
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
01126360
Message ID:
01126363
Views:
17
>I have a question here. In VFP, I used to get files through http using some code like this:
>
>
>loHttp = CREATEOBJECT("msxml2.xmlhttp.4.0")
>loHttp.open("GET", "http:\\SomeServer\SomeFile.zip")
>loHttp.send()
>STRTOFILE(loHttp.responseBody, "c:\SomeFile.zip")
>
>
>How can I accomplish that kind of thing in .NET?
>
>Another thing that I also have to do is to programmatically authenticate on the server. When I manually navigate to the file, I must provide username/password. How do I do that programmatically?
        ' Get the HTML response from a server
        ' expC1 Url
        Public Function GetUrl(ByVal tcUrl As String) As String
            Dim lcHTML As String
            Dim loHTTP As System.Net.WebClient = New System.Net.WebClient
            Dim loEncoding As System.Text.Encoding = Nothing
            Dim loRequestedHTML() As Byte
            Try
                loRequestedHTML = loHTTP.DownloadData(tcUrl)
                lcHTML = loEncoding.GetString(loRequestedHTML)
            Catch loError As Exception
                lcHTML = loError.Message
            End Try
            Return lcHTML
        End Function


        ' Get the HTML response from a server for a basic authentication
        ' expC1 Url
        ' expC2 Username
        ' expC3 Password
        Public Function GetUrlBasicAuthentication(ByVal tcUrl As String, ByVal tcUsername As String, ByVal tcPassword As String) As String
            Dim lcHTML As String
            Dim lcUrl As New System.Uri(tcUrl)
            Dim loHTTP As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create(lcUrl)
            loHTTP.Credentials = New System.Net.NetworkCredential(tcUsername, tcPassword)
            Try
                Dim loWebResponse As System.Net.WebResponse = loHTTP.GetResponse()
                Dim loStream As System.IO.Stream = loWebResponse.GetResponseStream()
                Dim loString As New System.IO.StreamReader(loStream)
                lcHTML = loString.ReadToEnd()
            Catch loError As Exception
                lcHTML = loError.Message
            End Try
            Return lcHTML
        End Function
Michel Fournier
Level Extreme Inc.
Designer, architect, owner of the Level Extreme Platform
Subscribe to the site at https://www.levelextreme.com/Home/DataEntry?Activator=55&NoStore=303
Subscription benefits https://www.levelextreme.com/Home/ViewPage?Activator=7&ID=52
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform