tags:

views:

43

answers:

3

Could anyone help me please ?

I need to download a file from web i.e https:\www.xxx.com\ using vb.net and save it to C drive of system.

Below is the code :

Dim URI As String = ftpHost & ftpFile
Dim oRequest As System.Net.HttpWebRequest = CType(HttpWebRequest.Create(URI), HttpWebRequest)
oRequest.Credentials = New System.Net.NetworkCredential(userName, pwd)        
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(localFile, 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

But this is not reading anything.

Thanks in advance.

A: 

take a look at this http://www.devhood.com/messages/message_view-2.aspx?thread_id=39924

Louis Rhys
That Doesn't help , i don't need proxy. Please see the code i have been using.
Swapnil
+1  A: 

I ran your code downloading the latest jQuery library from https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js and everything worked fine. I used a dummy username/password of 'name'/'pwd'. The only thing I can think of is that your credentials aren't valid. If you change your code to download the jQuery file I mentioned above, does it work? If it does, I'd take a look at the creds you're passing and also how you're processing them on the server side.

Hope this helps.

---modified code---

    Dim URI As String = "https://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.js"
    Dim oRequest As System.Net.HttpWebRequest = CType(HttpWebRequest.Create(URI), HttpWebRequest)
    oRequest.Credentials = New System.Net.NetworkCredential("name", "pwd")
    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("c:\temp\jquery-1.4.2.js", 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
David Hoerster
One thing I also noticed is that if I change the URL to use jQuery's CDN (https://code.jquery.com/jquery-1.4.2.min.js), I get an exception when GetResponse is called. I think the code.jquery.com cert is expired -- so maybe that's a problem, too.
David Hoerster
A: 

Does your target site https://foo.com/bar.txt present a certificate for foo.com or another site?

If it doesn't have a cert for foo.com, this might be part of the problem.

p.campbell