473,544 Members | 2,517 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 30060
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
8355
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 =...
0
2622
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...
1
2390
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
11405
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...
7
40946
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...
1
4983
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...
3
25800
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
5404
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...
0
2836
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...
0
7378
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...
0
7638
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. ...
1
7400
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...
1
5314
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...
0
3437
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...
0
3429
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1857
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1000
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
684
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...

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.