开发者

How to read a web file protected with .htaccess from VB.NET

开发者 https://www.devze.com 2023-04-04 17:50 出处:网络
I need to access a XML file located in a secured location on a web server. The security of the file is done using htaccess.

I need to access a XML file located in a secured location on a web server. The security of the file is done using htaccess. How can I read from VB.NET (or any .NET) this file, providin开发者_运维百科g the necessary credentials ?


I assume you mean that you need to supply a username and password.

To do this, set a Credentials object on the HttpWebRequest. See the documentation for more information and an example:

http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.credentials.aspx


If you are using a WebClient to retrieve the file, supply it with a NetworkCredential object like so:

Dim wc As New WebClient() With {
    .Credentials = New NetworkCredentials("MyUserName", "MyPassword")
}
0

精彩评论

暂无评论...
验证码 换一张
取 消