473,473 Members | 1,415 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

'download a file through proxy' code problem

Hi,

I am trying to download a file from the Internet. The below code
works fine with no proxy server but I am behind a proxy server at work
and need to figure out how to include it in the code.

<code>
Dim wc As New System.Net.WebClient
wc.DownloadFile("http://www.google.ie/images/hp0.gif", _
"C:\inetpub\wwwroot\bin\google.gif")
</code>

I have been looking all over google and am trying the following code
but as i am not familar with vb.net i can not get the structure right
or am not sure if this is the way to do it.
<code>
dim ProxyObject as New WebProxy= new
webProxy(Http://proxyserverIP:8080,true)
dim cred as NetworkCredential= new
NetworkCredential("User","password","domain")
ProxyObject.Credentials=cred
GlobalProxySelection.Select=proxyObject
<code>
Thanks for any and all help.
Nov 20 '05 #1
3 2237
In article <b3**************************@posting.google.com >, kieran5405
@hotmail.com says...
Hi,

I am trying to download a file from the Internet. The below code
works fine with no proxy server but I am behind a proxy server at work
and need to figure out how to include it in the code.

<code>
Dim wc As New System.Net.WebClient
wc.DownloadFile("http://www.google.ie/images/hp0.gif", _
"C:\inetpub\wwwroot\bin\google.gif")
</code>

I have been looking all over google and am trying the following code
but as i am not familar with vb.net i can not get the structure right
or am not sure if this is the way to do it.
<code>
dim ProxyObject as New WebProxy= new
webProxy(Http://proxyserverIP:8080,true)
dim cred as NetworkCredential= new
NetworkCredential("User","password","domain")
ProxyObject.Credentials=cred
GlobalProxySelection.Select=proxyObject
<code>


I've never gove through a proxy, but the above code looks correct.

However, the WebClient class doesn't have a Proxy property but the
WebRequest class does. You may have to use the WebRequest object and
stream the data into the file yourself.

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #2
Hi Patrick,

Cheers for response.

I have been trying what you said and can get the stream to read but
can not see how to write it. I am using the following code and keep
getting the error -

"Stream was not writable."
I see from other messages it may be something to do with 'Keep-alive'
but when i put in that line, it brings back an error. Or it may be
that the write syntax of my code is wrong.

Any help greatly appreciated.
------------------------
<code>
Dim sURL As String
sURL = "http://test.com/rss.xml"

Dim wrGETURL As WebRequest
wrGETURL = WebRequest.Create(sURL)

Dim saByPassList() As String
Dim myProxy As New WebProxy("proxy:8080", True, saByPassList, New
NetworkCredential("user", "password", "_domain"))

myProxy.BypassProxyOnLocal = True

wrGETURL.Proxy = myProxy
Dim objStream As Stream
objStream = wrGETURL.GetResponse.GetResponseStream()
Dim myFileName As String = "C:\rss.xml"
Dim myFileStream As New StreamWriter(objStream)
myFileStream = File.CreateText(myFileName)
</code>

---------------------------------------

Patrick Steele [MVP] <pa*****@mvps.org> wrote in message news:<MP************************@msnews.microsoft. com>...
In article <b3**************************@posting.google.com >, kieran5405
@hotmail.com says...
Hi,

I am trying to download a file from the Internet. The below code
works fine with no proxy server but I am behind a proxy server at work
and need to figure out how to include it in the code.

<code>
Dim wc As New System.Net.WebClient
wc.DownloadFile("http://www.google.ie/images/hp0.gif", _
"C:\inetpub\wwwroot\bin\google.gif")
</code>

I have been looking all over google and am trying the following code
but as i am not familar with vb.net i can not get the structure right
or am not sure if this is the way to do it.
<code>
dim ProxyObject as New WebProxy= new
webProxy(Http://proxyserverIP:8080,true)
dim cred as NetworkCredential= new
NetworkCredential("User","password","domain")
ProxyObject.Credentials=cred
GlobalProxySelection.Select=proxyObject
<code>


I've never gove through a proxy, but the above code looks correct.

However, the WebClient class doesn't have a Proxy property but the
WebRequest class does. You may have to use the WebRequest object and
stream the data into the file yourself.

Nov 20 '05 #3
In article <b3**************************@posting.google.com >, kieran5405
@hotmail.com says...
Hi Patrick,

Cheers for response.

I have been trying what you said and can get the stream to read but
can not see how to write it. I am using the following code and keep
getting the error -

"Stream was not writable." <code>

Dim sURL As String
sURL = "http://test.com/rss.xml"

Dim wrGETURL As WebRequest
wrGETURL = WebRequest.Create(sURL)

Dim saByPassList() As String
Dim myProxy As New WebProxy("proxy:8080", True, saByPassList, New
NetworkCredential("user", "password", "_domain"))

myProxy.BypassProxyOnLocal = True

wrGETURL.Proxy = myProxy

Dim objStream As Stream
objStream = wrGETURL.GetResponse.GetResponseStream()

Dim myFileStream As New StreamWriter(objStream)


I think you want to try a StreamReader instead of a StreamWriter (read
from the response stream of the webrequest).

--
Patrick Steele
Microsoft .NET MVP
http://weblogs.asp.net/psteele
Nov 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Martin Raychev | last post by:
Hi everybody, I have a need for a web app that will allow a flash client to download files at a specified speed. I am using Flash for an application of mine which downloads JPG slides to...
8
by: kieran | last post by:
Hi, I want to download an image from the web and save it locally. I have spent all day messing about with this and am still no where. We have a firewall so i use the below code. I know it...
5
by: Bala | last post by:
Hi I displaying my pdf files ( F:\test\test1\test.pdf - for example file path) on datagrid for user download. when I right clik the link and its show like this file:///F:/test/test1/test.pdf....
3
by: Matt D | last post by:
I've got two web services that use the same data types and that clients will have to consume. I read the msdn article on sharing types...
2
by: Volki | last post by:
I am using file upload download aspx code on my IIS 6.0, FW 1.1. I am uploading the files properly. However I am having problems on downloading the files in this code. Most of the browers I do not...
4
by: Nader Shahin | last post by:
I tried to develop an application to download a file from an Https server. My application was able to download a file from a regural Http server. I used a WebProxy and i passed the...
2
by: dclist | last post by:
What is the correct way to download a file through HTTP and save it to the file name suggested by "Content-Disposition"? I would use urlretrieve but I'm not sure how to obtain the file name...
2
by: Jobs | last post by:
Download the JAVA , .NET and SQL Server interview with answers Download the JAVA , .NET and SQL Server interview sheet and rate yourself. This will help you judge yourself are you really worth of...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.