Proxy Authentication Required

lroberts2006
02-09-2007, 07:05 PM
I am getting the follow error when I try to run my program because we use a proxy here at work. How can I add the proxy info to my program?

Thanks!

The remote server returned an error: (407) Proxy Authentication Required.

Here is my code...

' Check For Weather Alerts From WeatherBug
Dim MyConn As ADODB.Connection
Dim MyRecSet As ADODB.Recordset
Dim Alerts As XmlNodeList
Dim doc As New XmlDocument
Dim alertnode As XmlNode
Dim alert As Decimal

doc.Load("http://a7578597773.api.wxbug.net/getalerts.aspx?acode=A7578597773&zipcode=49501")

Alerts = doc.GetElementsByTagName("aws:alerts")

For Each alertnode In Alerts
alert += Decimal.Parse(alertnode.ChildNodes(0).Value)
Next
RichTextBox1.Text = Alerts.ToString()

I can not figure out how to add the Credential information to this for a proxy.... PLEASE HELP! I am 100% lost on this... Been at it for two days... :-(

lroberts2006
02-10-2007, 04:15 AM
:huh: :huh: This is driving me nuts.... I can not figure this out and can't seem to find anything on how to do it... :huh: S.O.S.!

Thanks!

lroberts2006
02-10-2007, 05:42 AM
Well I tried this but its not working either... I just dont get it. :huh:

' Check For Weather Alerts From WeatherBug
Dim MyConn As ADODB.Connection
Dim MyRecSet As ADODB.Recordset
Dim Alerts As XmlNodeList
Dim doc As New XmlDocument
Dim alertnode As XmlNode
Dim alert As Decimal

Dim myProxy As New WebProxy()
Dim newUri As New Uri("xxxxxxxxx")
myProxy.Address = newUri
myProxy.Credentials = New NetworkCredential("xxxxx", "xxxxx")

doc.Load("http://a7578597773.api.wxbug.net/getalerts.aspx?acode=A7578597773&zipcode=49501")
Alerts = doc.GetElementsByTagName("aws:alerts")

For Each alertnode In Alerts
alert += Decimal.Parse(alertnode.ChildNodes(0).Value)
Next
RichTextBox1.Text = Alerts.ToString()


The problem I see to is alot of this stuff does not seem to work with that load command. :-(

lroberts2006
02-10-2007, 06:56 PM
Does anyone have any idea? I mean maybe the load statement is not the right one to use for something like this... I need to be able to load a XML page from the net and look at it but from behind a proxy.

I really could use some help or idea here.

Dim myProxy As New WebProxy()
Dim newUri As New Uri("xxxxxxxxx")
myProxy.Address = newUri
myProxy.Credentials = New NetworkCredential("xxxx", "xxxxxx")
doc.Load("http://a7578597773.api.wxbug.net/getalerts.aspx?acode=A7578597773&zipcode=49501")

The question is, how do I connect the proxy information to the doc.load area so it knows to use the proxy?





Thanks guys!

Jabo
02-10-2007, 07:37 PM
Well I did a bit of digging feeling bad for you ;) I haven't done anything with a proxy before but I stumbled upon the System.Net.WebClient Namespace. That seems like more of what you need in my opinion. It has properties for Credentials/Proxy and has download/read with URIs etc. Hope this helps in some way.

lroberts2006
02-10-2007, 07:39 PM
:huh: Hey thanks for looking. Yeah I have looked at that, the issue is I can not figure out hot to connect that information to the doc.load statement. This one is really throwing me and I can't seem to find anything on it. I see alot of options out there for get normal web pages with a proxy but not for getting XML.

Jabo
02-10-2007, 07:50 PM
Well you might can use the read() on that namespace to read the page into a file or something and then then just load the file locally. But I don't think you can actually tell the document to use a proxy as it is expecting a file name. Your best bet is to just use the credintials and load the page into a file or stream and then read it from your doc.

lroberts2006
02-10-2007, 07:55 PM
Hhhhhhhmmmmm Any idea how I would do that? :huh:

Jabo
02-10-2007, 08:02 PM
Try this. I don't have a proxy to mess with credentials but once you have the credentials.


Dim myProxy as New Net.WebClient()
myProxy.DownloadFile("http://a7578597773.api.wxbug.net/getalerts.aspx?acode=A7578597773&zipcode=49501", "C:\test.xml")' It does create the file if it doesn't exist.


Then you can read the xml file in with an xml reader or w/e you like =) Goodluck. Don't hesistate to ask anything else.

lroberts2006
02-10-2007, 08:05 PM
Hey thanks a TON!!!!! I will play around with doing it this way and see what I get. MAJOR BIG THANKS!!! :D

lroberts2006
02-10-2007, 08:45 PM
Ok I am still stuck I guess... I am still getting the same error like it does not see the proxy information. Here is my code now... What am I doing wrong? The error says "Proxy Authentication Required "


Dim myProxy As New Net.WebClient()
myProxy.Credentials = New NetworkCredential("username", "password")
myProxy.BaseAddress = ("proxy address")
myProxy.DownloadFile("http://a7578597773.api.wxbug.net/getalerts.aspx?acode=A7578597773&zipcode=49501", "C:\test.xml")

Thanks!

Jabo
02-10-2007, 10:09 PM
Ok Try not setting the Credentials but the DefaultCredentials. Like I said, I don't have a proxy to test it out on. But from what I read defaultcredentials is more likely to be the answer for this. I don't know though. Try not setting specific credentials and making the UseDefaultCredentials to True and see where that goes.

If that is a no go. I stumbled upon this way. It looks similar but it might work better o_0 who knows.

' Create a request for the URL.
Dim request As WebRequest = WebRequest.Create("http://www.contoso.com/default.html")
' If required by the server, set the credentials.
request.Credentials = CredentialCache.DefaultCredentials
' Get the response.
Dim response As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)


By the looks of it you need to set the CredentialCache.DefaultCredentials is you need specific username/password.

lroberts2006
02-10-2007, 11:05 PM
The problem is that this uses WebRequest as to where I need to either use doc.load or myProxy.DownloadFile. :huh:

So I need one of the two ways here....

myProxy.DownloadFile("http://a7578597773.api.wxbug.net/getalerts.aspx?acode=A7578597773&zipcode=49501", "C:\test.xml")

Or

doc.Load("http://a7578597773.api.wxbug.net/getalerts.aspx?acode=A7578597773&zipcode=49501")

To work by feeding the proxy info.

I did try this....

Dim myProxy As New Net.WebClient
'myProxy.BaseAddress = ("xxxxxxxxxxxxx")
myProxy.Credentials = CredentialCache.DefaultCredentials
myProxy.DownloadFile("http://a7578597773.api.wxbug.net/getalerts.aspx?acode=A7578597773&zipcode=49501", "C:\test.xml")

But I still get the same thing... Proxy Authentication Required

:-((((((((((((((((

lroberts2006
02-12-2007, 11:44 AM
Ok now I am pulling my hair out... :huh: A week and I can not figure this out... There must be a simple way of doing this...

S.O.S.! Help!

Thanks

lroberts2006
02-15-2007, 07:31 PM
:huh:

lroberts2006
02-15-2007, 08:02 PM
Ok now I am really confused. From what I have been told is this...

If you are using .NET v1 then you need to have this line of code to read the default settings of IE. req.Proxy = WebProxy.GetDefaultProxy()

If you are using .NET v2 then your program should get the default settings from IE anyway.

Either way is not working :huh: :confused:

I am still getting Proxy Authentication Required.

The proxy info is set in our Internet Explorer 6.0

Its http://xxxxxxx.com Port 8080

When you try to visit some place, a popup comes up asking for network user name and password, once you give it.. The proxy moves on.

I can not for the life of me figure out how to get through this.....

Please help!!! thanks

Jabo
02-15-2007, 08:51 PM
Hmm. I still don't know but an old school way of loggin into websites used to be like something like Username:Password@www.mysite.com so maybe if you aren't showing the link you could just load manually with something like that. I can't exactly remember the syntax for the login tho

alex19063
02-15-2007, 10:06 PM
this is how I add proxy information to an HTTP POST (HttpWebRequest):


'set proxy if needed
If appProxySettings.useProxy = True Then

Dim myProxy As New WebProxy

'get Internet Explorer settings
'myProxy = WebProxy.GetDefaultProxy()'deprecated in Framework 2.0

'update existing settings with specified IP/address & port
Dim newUri As New Uri("http://" & appProxySettings.proxyIP & ":" & appProxySettings.proxyPort) ', True)''deprecated in Framework 2.0
myProxy.Address = newUri

If appProxySettings.useUsername = True Then

webrequest.AllowAutoRedirect = True
webrequest.AllowWriteStreamBuffering = True

' Create a NetworkCredential object and associate it with the Proxy property of myProxy object.
myProxy.Credentials = New NetworkCredential(appProxySettings.proxyUsername, appProxySettings.proxyPassword)
End If

webrequest.Proxy = myProxy
End If



note that "appProxySettings" is a structure defined in my app that stores all the communications settings (the settings form)

I spent 6 months to get my HTTP POSTs 100% it's a b*tch

lroberts2006
02-15-2007, 10:28 PM
Hey thanks but I just got it after 4 fricking weeks..... :huh:

Proxy is a 110% complete B***h in VB! Excuse my lango but darn this was really something. This is how I did it....

Imports System.IO
Imports System.Xml
Imports System.Net

Public Class Alert

Private alertLoc As String = "http://xxxxxxxxxx.api.wxbug.net/getAlertsRSS.aspx?ACode=xxxxxxxxxxx&zipCode=49508"
Private isAnyAlert As Boolean = False
Private alertDesc As String
Private errorWhileProcessing As Boolean = False
Private errorMessage As String
Private lastCheckedTime As String = "Never till started."



Private Function getRSSData(Optional ByVal ProxyAddress As String = "proxy.xxxx.com", Optional ByVal ProxyPort As Integer = 8080, Optional ByVal UserName As String = "xxxxxx", Optional ByVal PassWord As String = "xxxxxxxx", Optional ByVal Domain As String = "") As String

'this function gets alerts from weatherbug.com in xml format
Dim req As HttpWebRequest
Dim res As HttpWebResponse = Nothing
Dim reader As StreamReader = Nothing
Dim xmlData As String

Try
req = WebRequest.Create(alertLoc)
Dim oProxy As New WebProxy(ProxyAddress, ProxyPort)
oProxy.Credentials = New NetworkCredential(UserName, PassWord)
req.Proxy = oProxy



I hope thats kinda easy to understand. This was really something else and it would be nice to see a sticky someplace about how to do a proxy step by step. :-)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum