在streamreader VB.NET中指定用户名/密码 [英] Specifying username/password in streamreader VB.NET

查看:83
本文介绍了在streamreader VB.NET中指定用户名/密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用指定用户自动流文本文件到文本框并传入流阅读器



StreamReader:



i am trying auto stream text file to textbox with specifying user and pass in stream reader

StreamReader:

Dim address As String = "http://www.domaintest.com/test/file.txt"
        Dim webclient As NetworkCredential = "user:pass"
        Dim client As WebClient = New WebClient()
        Dim reader As StreamReader = New StreamReader(client.OpenRead(address))
        TextBox1.Text = reader.ReadToEnd





文件位置受htaccess保护



我有什么试过:



请指教用户名/密码



File Location Protected by htaccess

What I have tried:

Please Help me for Stream text file to text box with Specifying username/password

推荐答案

StreamReader不会获取任何内容的凭据。您正在寻找的是设置您创建的WebClient实例的Credentials属性。 (你也有一些非常糟糕的变量名,比如webclient,它不是WebClient实例!)

StreamReader doesn't take credentials for anything. What you're looking for is setting the Credentials property of the WebClient instance you created. (You also have some really bad variable names, like "webclient", which isn't a WebClient instance!)
Dim credentials = new NetworkCredential(username, password)
Dim webClient As New WebClient()
webClient.Credentials = credentials
Dim reader As New StreamReader(client.OpenRead(address))


这篇关于在streamreader VB.NET中指定用户名/密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆