473,888 Members | 1,437 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

WebClient & Proxy (407 Proxy authentication required)

I'm trying to download a file. I've tried both using webclient and the
httpWebRequest. Either way it returns a "407 proxy authentication
required".

The program is to be run externally, so basically I don't know the
users login-name, password or domain. So that makes setting the proxy
in code irrelevant, doesn't it?

When searching the web it appears to be a common problem. But I
haven't found my solution and still can't get it to work...

This the code I'm trying to execute:

'---
Function DownloadVersion File() As Boolean

LocalVersionfil e = Application.Exe cutablePath
LocalVersionfil e = LocalVersionfil e.Substring(0,
LocalVersionfil e.Length - 19) & "vk.txt"

Dim wctl As New WebClient
Try
wctl.DownloadFi le(versionFile, LocalVersionfil e)
DownloadVersion File = True
Catch ex As Exception
MsgBox(ex.Messa ge, MsgBoxStyle.Exc lamation, "Fejl i
DownloadVersion File")
DownloadVersion File = False
End Try

End Function
'----
Another part of my code that fails with same error:
'---
Dim myURI As Uri, url As String

url = FileToDownload( )
myURI = New Uri(url)

Try
Dim obj_HTTPWebRequ est As HttpWebRequest =
CType(HttpWebRe quest.Create(ur l), HttpWebRequest)
obj_HTTPWebRequ est.Credentials =
CredentialCache .DefaultCredent ials
Dim obj_HTTPWebResp onse As HttpWebResponse =
obj_HTTPWebRequ est.GetResponse ()
lFileSize = (obj_HTTPWebRes ponse.ContentLe ngth)
Catch ex As Exception
MsgBox(Err.Numb er)
MsgBox(ex.Messa ge, MsgBoxStyle.Exc lamation, "Fejl i
DownloadNewVers ionFile")
Application.Exi t()
End Try

'---
Thx in advance!

Regards /Snedker
Nov 21 '05 #1
4 30089
I have tried your sample code here at work and I get the 407 as well. I think
you are going to have to specify the proxy setting, I don't know of anyway
round this.

Try:

Dim proxyObject As New System.Net.WebP roxy("http://999.999.999.999 :9999",
True)
obj_HTTPWebRequ est.Proxy = proxyObject
obj_HTTPWebRequ est.Proxy.Crede ntials =
System.Net.Cred entialCache.Def aultCredentials

Replace 999.999.999.999 :9999 with your proxy IP address and port number.

Hope this helps.
Chris.
"Morten Snedker" wrote:
I'm trying to download a file. I've tried both using webclient and the
httpWebRequest. Either way it returns a "407 proxy authentication
required".

The program is to be run externally, so basically I don't know the
users login-name, password or domain. So that makes setting the proxy
in code irrelevant, doesn't it?

When searching the web it appears to be a common problem. But I
haven't found my solution and still can't get it to work...

This the code I'm trying to execute:

'---
Function DownloadVersion File() As Boolean

LocalVersionfil e = Application.Exe cutablePath
LocalVersionfil e = LocalVersionfil e.Substring(0,
LocalVersionfil e.Length - 19) & "vk.txt"

Dim wctl As New WebClient
Try
wctl.DownloadFi le(versionFile, LocalVersionfil e)
DownloadVersion File = True
Catch ex As Exception
MsgBox(ex.Messa ge, MsgBoxStyle.Exc lamation, "Fejl i
DownloadVersion File")
DownloadVersion File = False
End Try

End Function
'----
Another part of my code that fails with same error:
'---
Dim myURI As Uri, url As String

url = FileToDownload( )
myURI = New Uri(url)

Try
Dim obj_HTTPWebRequ est As HttpWebRequest =
CType(HttpWebRe quest.Create(ur l), HttpWebRequest)
obj_HTTPWebRequ est.Credentials =
CredentialCache .DefaultCredent ials
Dim obj_HTTPWebResp onse As HttpWebResponse =
obj_HTTPWebRequ est.GetResponse ()
lFileSize = (obj_HTTPWebRes ponse.ContentLe ngth)
Catch ex As Exception
MsgBox(Err.Numb er)
MsgBox(ex.Messa ge, MsgBoxStyle.Exc lamation, "Fejl i
DownloadNewVers ionFile")
Application.Exi t()
End Try

'---
Thx in advance!

Regards /Snedker

Nov 21 '05 #2
On Thu, 25 Nov 2004 01:33:05 -0800, "Chris Podmore"
<Ch**********@d iscussions.micr osoft.com> wrote:

First of all, thanks for your help so far. I've gotten a bit further
since now I don't get any errors back from the server.

But...it just won't download the file. If I run it at home it works
fine, but from work through ISA and proxy, it doesn't.

I've tried setting the proxy explicitly with
Dim proxyObject As New System.Net.WebP roxy("http://PICASSO:8080",
True), but this doesn't help either.

Trying to read the filesize with ContentLength, -1 is returned. This
is the code:

Dim myURI As Uri, url As String
url = versionFile
myURI = New Uri(url)

LocalVersionfil e = Application.Exe cutablePath
LocalVersionfil e = LocalVersionfil e.Substring(0,
LocalVersionfil e.Length - 19) & "vk.txt"

Try
Dim proxyObject As New WebProxy
proxyObject.Get DefaultProxy()

Dim obj_HTTPWebRequ est As HttpWebRequest =
CType(HttpWebRe quest.Create(ur l), HttpWebRequest)

With obj_HTTPWebRequ est
.Proxy = proxyObject
.Proxy.Credenti als =
CredentialCache .DefaultCredent ials()
Dim obj_HTTPWebResp onse As HttpWebResponse =
..GetResponse()
lFileSize = (.ContentLength )
End With

Catch ex As Exception
MsgBox(ex.Messa ge)
Application.Exi t()
End Try

MsgBox("Filesiz e: " & lFileSize)
Thanks again. Your help is greatly appreciated!

/Snedker
Nov 21 '05 #3
I'm at a bit of a loss as to what your problem is now. We have ISA etc and
the following code works fine for me.

Sorry I can't be more help.
Chris.

Dim url As String = "http://www.microsoft.c om"
Dim obj_HTTPWebRequ est As HttpWebRequest = CType(HttpWebRe quest.Create(ur l),
HttpWebRequest)

'Remove these two lines to get 407 error
obj_HTTPWebRequ est.Proxy = System.Net.WebP roxy.GetDefault Proxy
obj_HTTPWebRequ est.Proxy.Crede ntials =
System.Net.Cred entialCache.Def aultCredentials

Dim r As WebResponse = obj_HTTPWebRequ est.GetResponse ()

MsgBox(r.Conten tLength.ToStrin g)
"Morten Snedker" wrote:
On Thu, 25 Nov 2004 01:33:05 -0800, "Chris Podmore"
<Ch**********@d iscussions.micr osoft.com> wrote:

First of all, thanks for your help so far. I've gotten a bit further
since now I don't get any errors back from the server.

But...it just won't download the file. If I run it at home it works
fine, but from work through ISA and proxy, it doesn't.

I've tried setting the proxy explicitly with
Dim proxyObject As New System.Net.WebP roxy("http://PICASSO:8080",
True), but this doesn't help either.

Trying to read the filesize with ContentLength, -1 is returned. This
is the code:

Dim myURI As Uri, url As String
url = versionFile
myURI = New Uri(url)

LocalVersionfil e = Application.Exe cutablePath
LocalVersionfil e = LocalVersionfil e.Substring(0,
LocalVersionfil e.Length - 19) & "vk.txt"

Try
Dim proxyObject As New WebProxy
proxyObject.Get DefaultProxy()

Dim obj_HTTPWebRequ est As HttpWebRequest =
CType(HttpWebRe quest.Create(ur l), HttpWebRequest)

With obj_HTTPWebRequ est
.Proxy = proxyObject
.Proxy.Credenti als =
CredentialCache .DefaultCredent ials()
Dim obj_HTTPWebResp onse As HttpWebResponse =
..GetResponse()
lFileSize = (.ContentLength )
End With

Catch ex As Exception
MsgBox(ex.Messa ge)
Application.Exi t()
End Try

MsgBox("Filesiz e: " & lFileSize)
Thanks again. Your help is greatly appreciated!

/Snedker

Nov 21 '05 #4
On Thu, 25 Nov 2004 03:43:03 -0800, "Chris Podmore"
<Ch**********@d iscussions.micr osoft.com> wrote:
I'm at a bit of a loss as to what your problem is now. We have ISA etc and
the following code works fine for me. Sorry I can't be more help.
Don't be - you've helped plenty !! :-)
Dim r As WebResponse = obj_HTTPWebRequ est.GetResponse ()


I had
Dim r As HttpWebResponse = .GetResponse()
which is why it didn't work.

But with your help in regards to the proxy, and my little typo, I'm on
the right track...and all is working!

Thanks a lot!
Mr. Happy-Dude :-)
Nov 21 '05 #5

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

Similar topics

6
8373
by: JezB | last post by:
I'm getting the above error thrown somewhere in the code: XPathDocument xPathDocument = new XPathDocument(FileLocation); XPathNavigator xPathNavigator = xPathDocument.CreateNavigator(); XPathNodeIterator nodeIterator = xPathNavigator.Select("/plist/dict"); nodeIterator.MoveNext(); nodeIterator = nodeIterator.Current.SelectChildren(XPathNodeType.All); where FileLocation contains the full path of a local XML file. Why is this trying to...
0
2646
by: George | last post by:
Hello, I'm running an ASPX application "WebApplication1" which consumes a web service (service1.asmx) hosted on a machine with IP (128.1.7.x) . The web service is located in the intranet. The web methods can be invoked successfully if "WebApplication1" is located in machines with the same subnet (128.1.7.x). However, it fails if "WebApplication1" is hosted on
1
2418
by: Ily | last post by:
Hi I have the following code: Dim cred1 As New System.Net.NetworkCredential("myusername", "mypassword", "mydomainname") Dim cc As New System.Net.CredentialCache cc.Add(New Uri("http://www.yahoo.com"), "Basic", cred1) Dim wp As System.Net.WebProxy = New
2
11439
by: rcp | last post by:
Hi all, I've read all posts from all existing threads and none of them worked to solve my problem, although its exactly the same. I'll try to explain my case and see if a kind soul could help me out: I've a win32 service in C# on a client machine A, which accesses a WS (C#) on a server machine B (hosted on an IIS) Case 1: If I try to add the WSDL for the WS through VS2005, the 'Discovery
7
40992
by: chandru1782 | last post by:
Dear friends, I am trying to use CPAN for installing some perl modules. i am using a ubuntu system, which has internet connection through lan and authenticated proxy. when trying to install cpan.pm , it gives the following error, can any one help, You have no /root/.cpan/sources/MIRRORED.BY I'm trying to fetch one CPAN: LWP::UserAgent loaded ok Fetching with LWP:
1
5008
by: =?Utf-8?B?Z2FsbGFu?= | last post by:
We have an application that is running fine on several of our customer’s servers. However, one of our customers is having a problem running the application. The application works on one of his Windows 2003 servers, but not on the other one. The application is a C++ .Net /clr Windows Service. It communicates with our server by sending and receiving XML using the WebClient object. The error they are receiving is “The remote server...
3
25818
by: Learning.Net | last post by:
Hi All, I have an windows application created in C# &it is running fine on several of our customer. It does a httpWebrequest in the background. Everything was working fine but some customer are facing "The Remote server returned an error :(407) Proxy Authentication Required " {
2
5428
by: krishnakrish | last post by:
Hi, My name is krishna. I am using asp.net 2.0 with C#. I amusing Windows XP professional as OS. When I post some data to an external web server I get the error as "The Remote server returned an error :(407) Proxy Authentication Required ". Here is the code I am using, Please help me out at the earliest. public void JACCS_Response(string date,string jaccs_id,string irn,string company_id,string xmlid) { string...
0
2864
by: malkin | last post by:
Hi all, I have an external application that calls WebClient to download a file from our server. It runs fine without any proxy server involved. However, once there is a proxy server layer, it throws a 407 proxy authentication required error. My question is that since I do not know whether the users are going to download a file thru a proxy, is there a way in C# to specify a general way of coding to handle proxy and non-proxy users? ...
0
9800
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
11181
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...
1
10886
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
10439
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...
1
7990
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
7148
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
6014
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
4245
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3252
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.