VB.NET从HTTPS错误下载文件 [英] VB.NET download file from HTTPS Bugs

查看:85
本文介绍了VB.NET从HTTPS错误下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用于从HTTPS下载文件的代码

I have a code for downloading file from HTTPS

Dim URI As String = "https://secure.ddcos.com/MOVEitISAPI/MOVEitISAPI.310/action=hu_downld!parm=e930810185440778334!NoAttach=1/98677_5050854223051_942963.jpg"
Dim oRequest As System.Net.HttpWebRequest = CType(HttpWebRequest.Create(URI), HttpWebRequest)
oRequest.Credentials = New System.Net.NetworkCredential("username", "password")
Using oResponse As System.Net.WebResponse = CType(oRequest.GetResponse, System.Net.WebResponse)
    Using responseStream As IO.Stream = oResponse.GetResponseStream
        Using fs As New IO.FileStream("D:\98677_5050854223051_942963.jpg", FileMode.Create, FileAccess.Write)
            Dim buffer(2047) As Byte
            Dim read As Integer
            Do
                read = responseStream.Read(buffer, 0, buffer.Length)
                fs.Write(buffer, 0, read)
            Loop Until read = 0
            responseStream.Close()
            fs.Flush()
            fs.Close()
        End Using
        responseStream.Close()
    End Using
    oResponse.Close()
End Using
MsgBox("done")


我可以创建一个文件,但是它没有数据(0字节)大小,不知道为什么会发生这种情况

但是当我使用这个网站时,


I can create a file but it has no data(0 byte) size, don''t know why that happen

But when I use this site,

Dim URI As String = "https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"
oRequest.Credentials = New System.Net.NetworkCredential("", "")


我可以成功下载文件,

那么上面的代码有什么问题呢?任何建议表示赞赏.

谢谢. . .


修订:
我在互联网上找到了东西,我不知道这是否正确.
ClientCertificate集合 [


I can download the file successfully,

So what''s wrong with the above code? Any suggestion appreciated.

Thanks. . .


Revision:
I found something in the Internet, I don''t know if this is correct.
ClientCertificate Collection[^]
To access to the Web Server(https), a Client Browser must send/have a ClientCertificate, so if that''s the case how can I have a ClientCertificate?

推荐答案

您需要登录,然后在同一会话中下载.

也就是说,需要先登录页面并发布身份验证数据(假设这仅是一个带有HttpWebRequest.Method"POST"的HTTP请求),然后您才可以请求下载.

请参阅此讨论和代码示例:
http://stackoverflow.com/questions/542024/httpwebrequest-with-https-in-c [ ^ ],
http://social.msdn.microsoft.com /forums/zh-CN/Vsexpressvb/thread/c67a65f3-2696-4afe-962e-59760a442217/ [
You need to log in and then download in the same session.

That said need go to log in page and post authentication data first (assuming this is nothing more than one more prior HTTP request with HttpWebRequest.Method "POST") and only then you can do you request do download.

Please see this discussions and code samples:
http://stackoverflow.com/questions/542024/httpwebrequest-with-https-in-c[^],
http://social.msdn.microsoft.com/forums/en-US/Vsexpressvb/thread/c67a65f3-2696-4afe-962e-59760a442217/[^].

What exactly to do depends on how log in page works, but you should get the idea.

—SA


这篇关于VB.NET从HTTPS错误下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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