我尝试使用用户自动将文本文件流式传输到TextBox
,并在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
答案 0 :(得分:0)
Dim postUrl As String = "Your URL"
Dim request As WebRequest = WebRequest.Create(postUrl)
request.UseDefaultCredentials = False
request.Proxy = WebRequest.DefaultWebProxy
Dim nc As new NetworkCredential("UserName", "Password")
request.Proxy.Credentials = nc
request.Timeout = 10000
request.Method = "POST"
Dim response As WebResponse = request.GetResponse()
Dim strmResp As System.IO.Stream = response.GetResponseStream()
Dim strmReader As System.IO.StreamReader = new System.IO.StreamReader(strmResp, System.Text.Encoding.GetEncoding("utf-8"))
Dim resp As String = strmReader.ReadToEnd()
strmReader.Close()
答案 1 :(得分:0)
您的原始示例实际上返回了文件而未指定凭据。但是,如果要指定凭据,则可以执行此操作
Dim address As String = "http://www.domaintest.com/test/file.txt"
Dim credentials As New NetworkCredential("user", "pass")
Using client As New WebClient()
client.Credentials = credentials
Using reader As New StreamReader(client.OpenRead(address))
TextBox1.Text = reader.ReadToEnd
End Using
End Using