Click here to Skip to main content
15,884,933 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
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")

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("", "")

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?
Posted
Updated 9-Jun-11 1:16am
v6
Comments
Sergey Alexandrovich Kryukov 8-Jun-11 14:06pm    
Does the site require authentication before you download? Then you need to log in as well.
--SA
hansoctantan 9-Jun-11 2:15am    
yes, you must login first before downloading a file(in manual using a Browser), but same happens when I login and try to download using my program, don't know whats wrong with it.
Sergey Alexandrovich Kryukov 12-Jun-11 18:19pm    
In this case, you have my answer.
Still a problem?
--SA
Prerak Patel 9-Jun-11 4:25am    
What about anonymous access? Have you restricted?
hansoctantan 10-Jun-11 2:11am    
what did you mean?

1 solution

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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900