?
Solved

System.Net.WebRequest under proxy environment

Posted on 2008-11-11
3
Medium Priority
?
1,379 Views
Last Modified: 2012-06-21
I am unable to communicate to web urls using system.net.webrequest under proxy enevironment.
I get "The underlying connection was closed: The remote name could not be resolved." error.
see below for sample code

Any help would be appreciated.

 I used both defaultcredentials and providing proxy user and password. I get the same error
Dim objRequest As Net.WebRequest
        Dim objStream As IO.Stream
        Dim objResponse As Net.WebResponse
        Dim objStreamReader As IO.StreamReader
        Dim retXML As String = ""
 
        Try
 
            objRequest = Net.WebRequest.Create(strURL)
            objRequest.Method = "POST"
            objRequest.Credentials = Net.CredentialCache.DefaultCredentials
 
            
                            objRequest.Proxy.Credentials = New NetworkCredential(m_strProxyUser, m_strProxyPass)
            
            If objData Is Nothing OrElse objData.Length = 0 Then
                objRequest.ContentLength = 0
            Else
 
                objRequest.ContentType = strContentType
                objRequest.ContentLength = objData.Length()
                objStream = objRequest.GetRequestStream
                objStream.Write(objData, 0, objData.Length)
                objStream.Flush()
                objStream.Close()
                objStream = Nothing
            End If
 
            ' geting respond XML
            objRequest.Timeout = CLng(1000) * 3600
            objStreamReader = New IO.StreamReader(objRequest.GetResponse().GetResponseStream, True)
 
            retXML = objStreamReader.ReadToEnd()
            objStreamReader.Close()
 
        Catch ex As Exception
            MsgBox("SendHTTPRequest" & ex.ToString)
        Finally
            objRequest = Nothing
            objStream = Nothing
            objResponse = Nothing
            objStreamReader = Nothing
        End Try
 
        Return retXML

Open in new window

0
Comment
Question by:Kakoroat
  • 2
3 Comments
 
LVL 4

Accepted Solution

by:
Mitzs earned 500 total points
ID: 22940606
we had the same issue and this his how we got around.

 
Dim MyWebProxy As WebProxy = New WebProxy(ConfigurationManager.AppSettings("ProxyAddress").ToString())
MyWebProxy.BypassProxyOnLocal = True
MyWebProxy.Credentials = New NetworkCredential(ConfigurationManager.AppSettings("ProxyUsername").ToString, ConfigurationManager.AppSettings("ProxyPassword").ToString, ConfigurationManager.AppSettings("ProxyDomain").ToString)
Dim objWebRequest As System.Net.HttpWebRequest
Dim objWebResponse As System.Net.HttpWebResponse
 
objWebRequest = CType(System.Net.WebRequest.Create(UrlRequestStringBuilder.ToString()), System.Net.HttpWebRequest)
objWebRequest.Proxy = MyWebProxy
objWebRequest.PreAuthenticate = True
objWebRequest.Accept = "*/*"
objWebRequest.ContentType = "text/xml"
objWebRequest.AllowAutoRedirect = True
objWebRequest.UserAgent = "Mozilla/4.0 (compatible;" + " MSIE 6.0; Windows NT 5.0; .NET CLR 1.0.3705)"
objWebResponse = CType(objWebRequest.GetResponse(), System.Net.HttpWebResponse)
0
 

Author Closing Comment

by:Kakoroat
ID: 31515795
Thanks for the answer. It worked.

I still dont understand why on some proxy environments, proxyaddress is not required. It just works with proxyuser and proxypassword.

Any idea why?

0
 

Author Comment

by:Kakoroat
ID: 22953288
Thanks for the answer. It worked.

I still dont understand why on some proxy environments, proxyaddress is not required. It just works with proxyuser and proxypassword.

Any idea why?
0

Featured Post

Transaction-level recovery for Oracle database

Veeam Explore for Oracle delivers low RTOs and RPOs with agentless transaction log backup and transaction-level recovery of Oracle databases. You can restore the database to a precise point in time, even to a specific transaction.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses
Course of the Month16 days, left to enroll

850 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question