Click here to Skip to main content
15,890,512 members
Home / Discussions / C#
   

C#

 
GeneralSingle quotes in query Pin
Reinier van de Wetering16-Feb-04 1:33
Reinier van de Wetering16-Feb-04 1:33 
GeneralRe: Single quotes in query Pin
Mazdak16-Feb-04 3:01
Mazdak16-Feb-04 3:01 
GeneralRe: Single quotes in query Pin
Verdant12316-Feb-04 11:16
Verdant12316-Feb-04 11:16 
GeneralPrintPreviewDialog Pin
brain2cpu16-Feb-04 1:10
professionalbrain2cpu16-Feb-04 1:10 
GeneralRe: PrintPreviewDialog Pin
Reinier van de Wetering16-Feb-04 1:41
Reinier van de Wetering16-Feb-04 1:41 
GeneralRe: PrintPreviewDialog Pin
Heath Stewart16-Feb-04 6:28
protectorHeath Stewart16-Feb-04 6:28 
GeneralRe: PrintPreviewDialog Pin
brain2cpu17-Feb-04 0:34
professionalbrain2cpu17-Feb-04 0:34 
GeneralHttpWebRequest problems... Pin
Shammut16-Feb-04 0:55
Shammut16-Feb-04 0:55 
Hi All,

I’ve an application that should do a huge number of HTTP requests using “POST” method as the following:

In a thread method:

<br />
while (!Stop)<br />
{<br />
<br />
   if (requestsArray.Count == 0)<br />
   {<br />
      Thread.Sleep(500);<br />
      continue;<br />
   }<br />
<br />
   hTTPRequest = (HttpWebRequest) HttpWebRequest.Create(url);<br />
   hTTPRequest.Proxy = new WebProxy("proxyServer", proxyPort);<br />
   hTTPRequest.Method = "POST";<br />
   hTTPRequest.KeepAlive = false;<br />
   hTTPRequest.SendChunked = true;<br />
   hTTPRequest.AllowWriteStreamBuffering = true;<br />
   hTTPRequest.ContentType = "application/x-www-form-urlencoded";<br />
   hTTPRequest.Timeout = 30000; (30 Secs)<br />
   hTTPRequest.ReadWriteTimeout = 30000;<br />
   string postData = "Some params and values";<br />
   byte[] Content = new byte[UTF8Encoding.UTF8.GetByteCount(postData.ToCharArray(), 0, postData.Length)];<br />
   UTF8Encoding.UTF8.GetBytes(postData, 0, postData.Length, Content, 0);<br />
   hTTPRequest.ContentLength = Content.Length;<br />
   Stream writeStream = hHTTPRequest.GetRequestStream();<br />
   try<br />
   {<br />
      writeStream.Write(Content, 0, Content.Length);<br />
      writeStream.Close();<br />
   }<br />
   catch<br />
   {<br />
      Log the error…<br />
   }<br />
}<br />


After two or three requests I got the following error logged in my database:
"The operation has timed-out."

But note that this request takes no time to be performed. I directly get this error before the time goes out! Or any network activity occurs!

Another point: Since I post to the same target, can I use one instance of HttpWebRequest instead of creating new instance per each request? Such as:

In the constructor:

<br />
hTTPRequest = (HttpWebRequest) HttpWebRequest.Create(url);<br />
hTTPRequest.Proxy = new WebProxy("proxyServer", proxyPort);<br />
hTTPRequest.Method = "POST";<br />
hTTPRequest.KeepAlive = false;<br />
hTTPRequest.SendChunked = true;<br />
hTTPRequest.AllowWriteStreamBuffering = true;<br />
hTTPRequest.ContentType = "application/x-www-form-urlencoded";<br />
hTTPRequest.Timeout = 30000; (30 Secs)<br />
hTTPRequest.ReadWriteTimeout = 30000;<br />


In the thread’s method:
<br />
string postData = "Some params and values";<br />
byte[] Content = new byte[UTF8Encoding.UTF8.GetByteCount(postData.ToCharArray(), 0, postData.Length)];<br />
UTF8Encoding.UTF8.GetBytes(postData, 0, postData.Length, Content, 0);<br />
hTTPRequest.ContentLength = Content.Length;<br />
Stream writeStream = hTTPRequest.GetRequestStream();<br />
try<br />
{<br />
    writeStream.Write(Content, 0, Content.Length);<br />
    writeStream.Close();<br />
}<br />
catch<br />
{<br />
    Log the error…<br />
} <br />


But for the second request I got the following error:
"This property cannot be set after writing has started."


Can anyone help me please? Sigh | :sigh:
GeneralRe: HttpWebRequest problems... Pin
Heath Stewart16-Feb-04 6:23
protectorHeath Stewart16-Feb-04 6:23 
GeneralRe: HttpWebRequest problems... Pin
Shammut16-Feb-04 8:04
Shammut16-Feb-04 8:04 
GeneralRe: HttpWebRequest problems... Pin
Heath Stewart16-Feb-04 8:56
protectorHeath Stewart16-Feb-04 8:56 
GeneralPassing a structure with array pointers to a Win32 DLL Pin
Member 88417915-Feb-04 22:15
Member 88417915-Feb-04 22:15 
GeneralRe: Passing a structure with array pointers to a Win32 DLL Pin
Mazdak15-Feb-04 23:31
Mazdak15-Feb-04 23:31 
GeneralRe: Passing a structure with array pointers to a Win32 DLL Pin
Heath Stewart16-Feb-04 6:18
protectorHeath Stewart16-Feb-04 6:18 
GeneralAdvanced File Property Pin
KriZ~15-Feb-04 19:21
sussKriZ~15-Feb-04 19:21 
GeneralRe: Advanced File Property Pin
Heath Stewart16-Feb-04 6:09
protectorHeath Stewart16-Feb-04 6:09 
Generalall C# user read ^_^ a windows made for C# programmers Plus a funny joke about C#n00b for everybody Pin
CSharp131415-Feb-04 18:38
CSharp131415-Feb-04 18:38 
GeneralRe: all C# user read ^_^ a windows made for C# programmers Plus a funny joke about C#n00b for everybody Pin
CWIZO16-Feb-04 8:21
CWIZO16-Feb-04 8:21 
GeneralSingle/Double.ToString() help Pin
Verdant12315-Feb-04 16:53
Verdant12315-Feb-04 16:53 
GeneralRe: Single/Double.ToString() help Pin
Werdna15-Feb-04 20:21
Werdna15-Feb-04 20:21 
GeneralRe: Single/Double.ToString() help Pin
Heath Stewart16-Feb-04 5:55
protectorHeath Stewart16-Feb-04 5:55 
GeneralFree C# Training Pin
Tony M John15-Feb-04 15:07
Tony M John15-Feb-04 15:07 
GeneralRe: Free C# Training Pin
Anonymous16-Feb-04 15:08
Anonymous16-Feb-04 15:08 
GeneralParsing Tab Delimited File Pin
Verdant12315-Feb-04 14:05
Verdant12315-Feb-04 14:05 
GeneralRe: Parsing Tab Delimited File Pin
Colin Angus Mackay15-Feb-04 14:24
Colin Angus Mackay15-Feb-04 14:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.