System.Net.WebRequest under proxy environment

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

KakoroatAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

MitzsCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
KakoroatAuthor Commented:
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
KakoroatAuthor Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.