Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Re: "The request was aborted: The connection was closed unexpectedly"

Reply
Thread Tools

Re: "The request was aborted: The connection was closed unexpectedly"

 
 
John Saunders
Guest
Posts: n/a
 
      07-16-2004
"Dave" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
>
> I'm trying to simulate a form post using the WebRequest class. But I

can't find this error (see note below) documented on MSDN.
>
> string strId = "someid";
> string strName = "somename";
>
> ASCIIEncoding encoding=new ASCIIEncoding();
>
> string postData="userid="+strId;
> postData += ("&username="+strName);
> byte[] data = encoding.GetBytes(postData);
>
> Prepare web request...
> HttpWebRequest myRequest =

(HttpWebRequest)WebRequest.Create("https://secure.somecontentwepayfor.com");
> myRequest.Method = "POST";
> myRequest.ContentType="application/x-www-form-urlencoded";
> myRequest.ContentLength = data.Length;
>
> Stream newStream=myRequest.GetRequestStream();
> newStream.Write(data,0,data.Length); <---**ERROR OCCURS HERE**.
> newStream.Close();
> WebResponse resp = myRequest.GetResponse();


Throw a try block around that code and display the full exception in the
catch. In addition, if it's a WebException, you may be able to display the
Status property:

try
{
string strId = "someid";
string strName = "somename";

ASCIIEncoding encoding=new ASCIIEncoding();

string postData="userid="+strId;
postData += ("&username="+strName);
byte[] data = encoding.GetBytes(postData);

Prepare web request...
HttpWebRequest myRequest =
(HttpWebRequest)WebRequest.Create("https://secure.somecontentwepayfor.com");
myRequest.Method = "POST";
myRequest.ContentType="application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;

Stream newStream=myRequest.GetRequestStream();
newStream.Write(data,0,data.Length); <---**ERROR OCCURS HERE**.
newStream.Close();
WebResponse resp = myRequest.GetResponse();
}
catch (WebException wex)
{
Page.Trace.Write(wex.ToString());
Page.Trace.Write(wex.Status);
}
catch (Exception ex)
{
Page.Trace.Write(ex.ToString());
}
--
John Saunders
johnwsaundersiii at hotmail


 
Reply With Quote
 
 
 
 
Kyril Magnos
Guest
Posts: n/a
 
      07-16-2004
What is the actual exception that is being thrown? That might help us figure
out what is going on.
--
HTH

Kyril Magnos

Question of the day:
What is Mono?
A) Disease where the lymph nodes become swollen.
B) A single sound
C) A synonym for one
D) A port of .NET meant to royally irritate MSFT
E) All of the above.

"Dave" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
| Thanks. I did all that but it doesn't really give me any insight as to
why it's happening.
|
| "John Saunders" wrote:
|
| > "Dave" <(E-Mail Removed)> wrote in message
| > news:(E-Mail Removed)...
| > > Hi,
| > >
| > > I'm trying to simulate a form post using the WebRequest class. But I
| > can't find this error (see note below) documented on MSDN.
| > >
| > > string strId = "someid";
| > > string strName = "somename";
| > >
| > > ASCIIEncoding encoding=new ASCIIEncoding();
| > >
| > > string postData="userid="+strId;
| > > postData += ("&username="+strName);
| > > byte[] data = encoding.GetBytes(postData);
| > >
| > > Prepare web request...
| > > HttpWebRequest myRequest =
| >
(HttpWebRequest)WebRequest.Create("https://secure.somecontentwepayfor.com");
| > > myRequest.Method = "POST";
| > > myRequest.ContentType="application/x-www-form-urlencoded";
| > > myRequest.ContentLength = data.Length;
| > >
| > > Stream newStream=myRequest.GetRequestStream();
| > > newStream.Write(data,0,data.Length); <---**ERROR OCCURS HERE**.
| > > newStream.Close();
| > > WebResponse resp = myRequest.GetResponse();
| >
| > Throw a try block around that code and display the full exception in the
| > catch. In addition, if it's a WebException, you may be able to display
the
| > Status property:
| >
| > try
| > {
| > string strId = "someid";
| > string strName = "somename";
| >
| > ASCIIEncoding encoding=new ASCIIEncoding();
| >
| > string postData="userid="+strId;
| > postData += ("&username="+strName);
| > byte[] data = encoding.GetBytes(postData);
| >
| > Prepare web request...
| > HttpWebRequest myRequest =
| >
(HttpWebRequest)WebRequest.Create("https://secure.somecontentwepayfor.com");
| > myRequest.Method = "POST";
| > myRequest.ContentType="application/x-www-form-urlencoded";
| > myRequest.ContentLength = data.Length;
| >
| > Stream newStream=myRequest.GetRequestStream();
| > newStream.Write(data,0,data.Length); <---**ERROR OCCURS HERE**.
| > newStream.Close();
| > WebResponse resp = myRequest.GetResponse();
| > }
| > catch (WebException wex)
| > {
| > Page.Trace.Write(wex.ToString());
| > Page.Trace.Write(wex.Status);
| > }
| > catch (Exception ex)
| > {
| > Page.Trace.Write(ex.ToString());
| > }
| > --
| > John Saunders
| > johnwsaundersiii at hotmail
| >
| >
| >


 
Reply With Quote
 
 
 
 
John Saunders
Guest
Posts: n/a
 
      07-16-2004
Please provide the stack trace...

--
John Saunders
johnwsaundersiii at hotmail


"Dave" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Thanks. I did all that but it doesn't really give me any insight as to

why it's happening.
>
> "John Saunders" wrote:
>
> > "Dave" <(E-Mail Removed)> wrote in message
> > news:(E-Mail Removed)...
> > > Hi,
> > >
> > > I'm trying to simulate a form post using the WebRequest class. But I

> > can't find this error (see note below) documented on MSDN.
> > >
> > > string strId = "someid";
> > > string strName = "somename";
> > >
> > > ASCIIEncoding encoding=new ASCIIEncoding();
> > >
> > > string postData="userid="+strId;
> > > postData += ("&username="+strName);
> > > byte[] data = encoding.GetBytes(postData);
> > >
> > > Prepare web request...
> > > HttpWebRequest myRequest =

> >

(HttpWebRequest)WebRequest.Create("https://secure.somecontentwepayfor.com");
> > > myRequest.Method = "POST";
> > > myRequest.ContentType="application/x-www-form-urlencoded";
> > > myRequest.ContentLength = data.Length;
> > >
> > > Stream newStream=myRequest.GetRequestStream();
> > > newStream.Write(data,0,data.Length); <---**ERROR OCCURS HERE**.
> > > newStream.Close();
> > > WebResponse resp = myRequest.GetResponse();

> >
> > Throw a try block around that code and display the full exception in the
> > catch. In addition, if it's a WebException, you may be able to display

the
> > Status property:
> >
> > try
> > {
> > string strId = "someid";
> > string strName = "somename";
> >
> > ASCIIEncoding encoding=new ASCIIEncoding();
> >
> > string postData="userid="+strId;
> > postData += ("&username="+strName);
> > byte[] data = encoding.GetBytes(postData);
> >
> > Prepare web request...
> > HttpWebRequest myRequest =
> >

(HttpWebRequest)WebRequest.Create("https://secure.somecontentwepayfor.com");
> > myRequest.Method = "POST";
> > myRequest.ContentType="application/x-www-form-urlencoded";
> > myRequest.ContentLength = data.Length;
> >
> > Stream newStream=myRequest.GetRequestStream();
> > newStream.Write(data,0,data.Length); <---**ERROR OCCURS HERE**.
> > newStream.Close();
> > WebResponse resp = myRequest.GetResponse();
> > }
> > catch (WebException wex)
> > {
> > Page.Trace.Write(wex.ToString());
> > Page.Trace.Write(wex.Status);
> > }
> > catch (Exception ex)
> > {
> > Page.Trace.Write(ex.ToString());
> > }
> > --
> > John Saunders
> > johnwsaundersiii at hotmail
> >
> >
> >



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HTTP::Proxy Error: "Getting request failed: Client closed" jason.yfho@gmail.com Perl Misc 0 01-20-2007 04:25 AM
Established connection aborted and underlying connection closed Apu Nahasapeemapetilon ASP .Net Web Services 0 11-06-2006 04:24 PM
HOW to solve ... System.Net.WebException: Connection closed etantonio@gmail.com ASP .Net 1 09-30-2005 12:05 PM
Re: Accessing Request.InputStream / Request.BinaryRead *as the request is occuring*: How??? Brian Birtle ASP .Net 2 10-16-2003 02:11 PM
Opera - .closed not accessible if window is closed? Matt Kruse Javascript 5 09-09-2003 01:27 AM



Advertisments