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 DownloadVersionFile() As Boolean
LocalVersionfile = Application.ExecutablePath
LocalVersionfile = LocalVersionfile.Substring(0,
LocalVersionfile.Length - 19) & "vk.txt"
Dim wctl As New WebClient
Try
wctl.DownloadFile(versionFile, LocalVersionfile)
DownloadVersionFile = True
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Fejl i
DownloadVersionFile")
DownloadVersionFile = 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_HTTPWebRequest As HttpWebRequest =
CType(HttpWebRequest.Create(url), HttpWebRequest)
obj_HTTPWebRequest.Credentials =
CredentialCache.DefaultCredentials
Dim obj_HTTPWebResponse As HttpWebResponse =
obj_HTTPWebRequest.GetResponse()
lFileSize = (obj_HTTPWebResponse.ContentLength)
Catch ex As Exception
MsgBox(Err.Number)
MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Fejl i
DownloadNewVersionFile")
Application.Exit()
End Try
'---
Thx in advance!
Regards /Snedker 4 30011
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.WebProxy("http://999.999.999.999:9999",
True)
obj_HTTPWebRequest.Proxy = proxyObject
obj_HTTPWebRequest.Proxy.Credentials =
System.Net.CredentialCache.DefaultCredentials
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 DownloadVersionFile() As Boolean
LocalVersionfile = Application.ExecutablePath LocalVersionfile = LocalVersionfile.Substring(0, LocalVersionfile.Length - 19) & "vk.txt"
Dim wctl As New WebClient Try wctl.DownloadFile(versionFile, LocalVersionfile) DownloadVersionFile = True Catch ex As Exception MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Fejl i DownloadVersionFile") DownloadVersionFile = 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_HTTPWebRequest As HttpWebRequest = CType(HttpWebRequest.Create(url), HttpWebRequest) obj_HTTPWebRequest.Credentials = CredentialCache.DefaultCredentials Dim obj_HTTPWebResponse As HttpWebResponse = obj_HTTPWebRequest.GetResponse() lFileSize = (obj_HTTPWebResponse.ContentLength) Catch ex As Exception MsgBox(Err.Number) MsgBox(ex.Message, MsgBoxStyle.Exclamation, "Fejl i DownloadNewVersionFile") Application.Exit() End Try
'---
Thx in advance!
Regards /Snedker
On Thu, 25 Nov 2004 01:33:05 -0800, "Chris Podmore"
<Ch**********@discussions.microsoft.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.WebProxy("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)
LocalVersionfile = Application.ExecutablePath
LocalVersionfile = LocalVersionfile.Substring(0,
LocalVersionfile.Length - 19) & "vk.txt"
Try
Dim proxyObject As New WebProxy
proxyObject.GetDefaultProxy()
Dim obj_HTTPWebRequest As HttpWebRequest =
CType(HttpWebRequest.Create(url), HttpWebRequest)
With obj_HTTPWebRequest
.Proxy = proxyObject
.Proxy.Credentials =
CredentialCache.DefaultCredentials()
Dim obj_HTTPWebResponse As HttpWebResponse =
..GetResponse()
lFileSize = (.ContentLength)
End With
Catch ex As Exception
MsgBox(ex.Message)
Application.Exit()
End Try
MsgBox("Filesize: " & lFileSize)
Thanks again. Your help is greatly appreciated!
/Snedker
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.com"
Dim obj_HTTPWebRequest As HttpWebRequest = CType(HttpWebRequest.Create(url),
HttpWebRequest)
'Remove these two lines to get 407 error
obj_HTTPWebRequest.Proxy = System.Net.WebProxy.GetDefaultProxy
obj_HTTPWebRequest.Proxy.Credentials =
System.Net.CredentialCache.DefaultCredentials
Dim r As WebResponse = obj_HTTPWebRequest.GetResponse()
MsgBox(r.ContentLength.ToString)
"Morten Snedker" wrote: On Thu, 25 Nov 2004 01:33:05 -0800, "Chris Podmore" <Ch**********@discussions.microsoft.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.WebProxy("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)
LocalVersionfile = Application.ExecutablePath LocalVersionfile = LocalVersionfile.Substring(0, LocalVersionfile.Length - 19) & "vk.txt"
Try Dim proxyObject As New WebProxy proxyObject.GetDefaultProxy()
Dim obj_HTTPWebRequest As HttpWebRequest = CType(HttpWebRequest.Create(url), HttpWebRequest)
With obj_HTTPWebRequest .Proxy = proxyObject .Proxy.Credentials = CredentialCache.DefaultCredentials() Dim obj_HTTPWebResponse As HttpWebResponse = ..GetResponse() lFileSize = (.ContentLength) End With
Catch ex As Exception MsgBox(ex.Message) Application.Exit() End Try
MsgBox("Filesize: " & lFileSize)
Thanks again. Your help is greatly appreciated!
/Snedker
On Thu, 25 Nov 2004 03:43:03 -0800, "Chris Podmore"
<Ch**********@discussions.microsoft.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_HTTPWebRequest.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 :-) This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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();...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: aa123db |
last post by:
Variable and constants
Use var or let for variables and const fror constants.
Var foo ='bar';
Let foo ='bar';const baz ='bar';
Functions
function $name$ ($parameters$) {
}
...
|
by: ryjfgjl |
last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
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...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
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...
| |