Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27353

VS 2005 downloading a file from HTTPS using proxy

$
0
0
This was suppose to be a simple task,what i wanna do is download a file lets say https://www.onlinesubmit.in/people-computers.jpg but the original file has limited to view in a particular region so i have to use a proxy service and i am using https://www.proxy-service.de/

so the complete link becomes https://www.proxy-service.de/proxy-s...&b=0&f=norefer

now i have to download it by my app not via web-browser,

when i try

Code:

Dim myclient As New WebClient
        Dim url As Uri = New Uri("https://www.onlinesubmit.in/people-computers.jpg")
        myclient.DownloadFileAsync(url, "pic.jpg")

this works fine but if i change the Uri to https://www.proxy-service.de/proxy-s...&b=0&f=norefer this don't work as may be proxy site doesn't support hotlinking.

so i google a bit and found some code which says i have to use
Code:

System.Net.WebProxy("http://proxy-service.de", True)
for HTTP and
Code:

System.Net.WebProxy("proxy-service.https.de",443)
for HTTPS

so i try to write some code

Code:

Try
            Dim proxy As New System.Net.WebProxy("proxy-service.https.de", 443)
            proxy.Credentials = New System.Net.NetworkCredential("userId", "password", "Domain")
            Dim URI As String = "https://www.onlinesubmit.in/people-computers.jpg"
            Dim oRequest As System.Net.HttpWebRequest = CType(System.Net.HttpWebRequest.Create(URI), System.Net.HttpWebRequest)
            oRequest.Proxy = proxy
            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("Downloaded_file.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
        Catch ex As Exception
            File.WriteAllText("error.txt", ex.ToString)
        End Try

and it's not working,it simply creates a blank jpg file and the exception as per error.txt is

Quote:

System.Net.WebException: The remote name could not be resolved: 'proxy-service.https.de'
at System.Net.HttpWebRequest.GetResponse()
at dummy_proj.Form1.Button1_Click(Object sender, EventArgs e) in C:\Documents and Settings\Owner\My Documents\Visual Studio 2005\Projects\dummy_proj\dummy_proj\Form1.vb:line 13
And now i am clue less,please help anybody anything? :sick:

Viewing all articles
Browse latest Browse all 27353

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>