473,810 Members | 3,142 Online
Bytes | Software Development & Data Engineering Community
+ 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.WebC lient
wc.DownloadFile ("http://www.google.ie/images/hp0.gif", _
"C:\inetpub\www root\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 NetworkCredenti al= new
NetworkCredenti al("User","pass word","domain")
ProxyObject.Cre dentials=cred
GlobalProxySele ction.Select=pr oxyObject
<code>
Thanks for any and all help.
Nov 20 '05 #1
3 2266
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.WebC lient
wc.DownloadFile ("http://www.google.ie/images/hp0.gif", _
"C:\inetpub\www root\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 NetworkCredenti al= new
NetworkCredenti al("User","pass word","domain")
ProxyObject.Cre dentials=cred
GlobalProxySele ction.Select=pr oxyObject
<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.Crea te(sURL)

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

myProxy.BypassP roxyOnLocal = True

wrGETURL.Proxy = myProxy
Dim objStream As Stream
objStream = wrGETURL.GetRes ponse.GetRespon seStream()
Dim myFileName As String = "C:\rss.xml "
Dim myFileStream As New StreamWriter(ob jStream)
myFileStream = File.CreateText (myFileName)
</code>

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

Patrick Steele [MVP] <pa*****@mvps.o rg> wrote in message news:<MP******* *************** **@msnews.micro soft.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.WebC lient
wc.DownloadFile ("http://www.google.ie/images/hp0.gif", _
"C:\inetpub\www root\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 NetworkCredenti al= new
NetworkCredenti al("User","pass word","domain")
ProxyObject.Cre dentials=cred
GlobalProxySele ction.Select=pr oxyObject
<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.Crea te(sURL)

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

myProxy.BypassP roxyOnLocal = True

wrGETURL.Proxy = myProxy

Dim objStream As Stream
objStream = wrGETURL.GetRes ponse.GetRespon seStream()

Dim myFileStream As New StreamWriter(ob jStream)


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
1397
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 users' web based app. Because I can't control how quickly a file (in this case, a JPG slide) is
8
2407
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 works down to the line as i also use this code to download an xml file from the net. I have been messing around with all sorts of ways to stream the image into a local file and save it. but no luck. Am i totally off key here, can anyone point me...
5
1690
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. But the problem is its not dowloading the file. I am impersontating the my domain user account. I am sure there is simple mistake, but I cannt find that one. anyone please help me. can i use server.mappath?
3
6513
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 (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnservice/html/service07162002.asp) but I don't want clients to have to add two web references and then manually have to edit the proxy classes. After doing some searching I found that putting references to multiple web services in a .disco...
2
1503
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 have any problem including Firefox. But some IE versions donloading the file but it is only 0 byte ?!? Any one knows this? Thank you so much.
4
5055
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 NetworkCredential, but also it didn't work like:- Dim myProxy As New WebProxy("https://TheServername.com/", 443) Also I used that way to create a class to accept all kinds of certifications, and also it didn't work.
2
6122
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 through the HTTP headers without downloading the body (e.g. urlopen(url).info()).
2
6971
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 attending interviews. If you own a company best way to judge if the candidate is worth of it. http://www.questpond.com/InterviewRatingSheet.zip
0
10644
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10379
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10393
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10124
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9200
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7664
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6882
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5550
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5690
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.