Re: System.Net.WebException

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Adrian D. Garcia (garcia.adrian_at_gmail.com)
Date: 09/15/04


Date: Wed, 15 Sep 2004 14:25:24 -0700

Thanks for the replay,

My network hasnt a proxy buy I m working with the idea....
Where I can configure the default proxy to the stack that .NET use to
connect to HTTP? The machine is a Windows XP Prof. with SP1. I was traiyng
with proxycfg but without luck.
Also I m looking at machine.config, at the systen.net section.
Why do you think that the ASP.NET app can connect and the conolse/windforns
apps dont? Wich are the difference between this type of app?

Thanks in advance

-- 
Adrian D. Garcia
MCSD
NDSoft Consultoria y Desarrollo
"Feroze [msft]" <ferozed@online.microsoft.com> wrote in message
news:41471fe9$1@news.microsoft.com...
> From the stack, it looks as if the app is trying to connect through proxy
> and failing,
>
> does your network have a http proxy that you need to use ? if so, set the
> proxy address in a WebProxy instance, and set the "proxy" property of the
> HttpWebRequest object.
>
> -- 
> feroze
>
> -----------------
> This posting is provided as-is. It offers no warranties and assigns no
> rights.
>
> See http://weblogs.asp.net/feroze_daud for System.Net related posts.
> ----------------
>
> "Adrian D. Garcia" <garcia.adrian@gmail.com> wrote in message
> news:eoF90MQmEHA.3544@TK2MSFTNGP15.phx.gbl...
> > Hi,
> > I m trying to connect to a HTTP Server using the HTTPWebRequest Class
but
> > I'm getting the following error:
> >
> > System.Net.WebException: The underlying connection was closed: Unable to
> > connect to the remote server. ---> System.Net.WebException: The
underlying
> > connection was closed: Unable to connect to the remote server.
> >    at System.Net.HttpWebRequest.CheckFinalStatus()
> >    at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
> >    at System.Net.HttpWebRequest.GetResponse()
> >    at System.Net.Connection.TunnelThroughProxy(Uri proxy, HttpWebRequest
> > originalRequest, Socket& socket)
> >    --- End of inner exception stack trace ---
> >    at System.Net.HttpWebRequest.CheckFinalStatus()
> >    at System.Net.HttpWebRequest.EndGetResponse(IAsyncResult asyncResult)
> >    at System.Net.HttpWebRequest.GetResponse()
> >    at Proceso.Proceso.MiRequest(String Method, String URL, String
> > DataToPost, NameValueCollection RequestHeaders, NameValueCollection&
> > ResponseHeaders, String URLReferer, String ContentType, String&
> ResponseURL)
> > in E:\_TF\Proceso.vb:line 67
> >
> > Here is the code that generate the problem:
> >
> >
> >
> > Public Function MiRequest(ByVal Method As String, ByVal URL As String
> > String, ByVal ContentType As String) As String
> >
> > Dim i As Integer
> >
> > Dim res As HttpWebResponse
> >
> > Dim req As HttpWebRequest
> >
> > Dim RequestStream As Stream
> >
> > Dim ReceiveStream As Stream
> >
> > Dim encode As Encoding
> >
> > Dim sr As StreamReader
> >
> > req = WebRequest.Create(URL)
> >
> > req.Method = Method
> >
> > 'req.Timeout = 12000
> >
> > req.KeepAlive = False
> >
> >
> >
> > req.ContentType = ContentType
> >
> > Dim SomeBytes() As Byte
> >
> > Dim UrlEncoded As New StringBuilder
> >
> > Dim reserved() As Char = {ChrW(63), ChrW(61), ChrW(38)}
> >
> >
> >
> > res = req.GetResponse()
> >
> > ReceiveStream = res.GetResponseStream()
> >
> > encode = System.Text.Encoding.GetEncoding("utf-8")
> >
> > sr = New StreamReader(ReceiveStream, encode)
> >
> > Dim read(256) As Char
> >
> > Dim count As Integer = sr.Read(read, 0, 256)
> >
> > Dim buffer As New System.Text.StringBuilder(1000)
> >
> > Do While count > 0
> >
> > buffer.Append(read, 0, count)
> >
> > count = sr.Read(read, 0, 256)
> >
> > Loop
> >
> > res.Close()
> >
> > Return buffer.ToString()
> >
> > End Function
> >
> >
> >
> > As you can see I m using the KeepAlive property to False. (KB
Suggestion).
> >
> > This code works fine inside an ASP.NET page but always generate the
prvius
> > error when I used inside a Console App or Windows Form App.
> >
> > The O.S. is Windows XP with SP 1 with Framework 1.1 installed.
> >
> > Any idea why its works inside an ASP.NET process but not in other
process?
> >
> > Regards.
> >
> > Adrian
> >
> >
> >
> >
> > -- 
> > Saludos
> > Adrian D. Garcia
> > MCSD
> > NDSoft Consultoria y Desarrollo
> >
> >
>
>


Relevant Pages

  • Re: System.Net.WebException
    ... it looks as if the app is trying to connect through proxy ... HttpWebRequest object. ... > at Proceso.Proceso.MiRequest(String Method, String URL, String ... > Dim res As HttpWebResponse ...
    (microsoft.public.dotnet.framework)
  • Active Directory gives up group info for only SOME users
    ... Our ASP.NET app is secured with forms authentication and validates users ... against Active Directory. ... Private _filterAttribute As String ... Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, ...
    (microsoft.public.dotnet.security)
  • AD only gives up group (role) information for SOME users
    ... Our ASP.NET app is secured with forms authentication and validates users ... against Active Directory. ... Private _filterAttribute As String ... Dim entry As DirectoryEntry = New DirectoryEntry(_path, domainAndUsername, ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: My.Application.CommandLineArgs
    ... (wrote every CommandLineArg followed by a vbCrLf just so I could read the log easier..) ... For Each _s As String In My.Application.CommandLineArgs ... Dim _sw As New IO.StreamWriter ... For a test I've copied a bunch of text files that im selecting and sending to my app through the send to menu. ...
    (microsoft.public.dotnet.languages.vb)
  • Connecting to ODBC DB at startup
    ... Oracle tables in the table list, it asks for an id and pass. ... The problem is when I go to run a query or do anything else in the app ... Dim cnConn As ADODB.Connection ... Dim strLogin As String ...
    (comp.databases.ms-access)