Has anyone got HTTPWebRequest and passing a post to an authenticated site to work on a Intel Dual Core Vista Business machine.?
We expect approx. 7Kbytes but afer approx. 3K the code then hangs
My code is shown below:
Thanks all
string FormUri = "http://wwwxxxxxxxx
string FormDataString = "xxxxxxxx"
// Post Form Data
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(FormUri);
CookieContainer cookieContainer = new CookieContainer();
req.CookieContainer = cookieContainer;
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
req.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; )";
req.Headers.Add(HttpRequestHeader.AcceptLanguage, "en-GB");
req.KeepAlive = true;
HttpRequestCachePolicy policy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCac heNoStore);
req.CachePolicy = policy;
req.Accept = "image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-shockwave-flash, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, */*";
req.Headers.Add("timeperiod", DateTime.UtcNow.ToLocalTime().ToShortTimeString()) ;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] FormDataBytes = encoding.GetBytes(FormDataString);
req.ContentLength = FormDataBytes.Length;
Stream stream = req.GetRequestStream();
stream.Write(FormDataBytes, 0, FormDataBytes.Length);
stream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse();
Application.DoEvents();
byte[] b = new byte[1];
int i = 0;
string temp = "";
Stream Strm = res.GetResponseStream();
byte[] a = ReadFully(Strm, 32768);
string response = System.Text.Encoding.ASCII.GetString(a);.
byte[] a = ReadFully(Strm, 32768);
public byte[] ReadFully(Stream stream, int initialLength)
{
/* If we've been passed an unhelpful initial length, just
use 32K. */
if (initialLength < 1)
{
initialLength = 32768;
}
byte[] buffer = new byte[initialLength];
int read = 0;
int chunk;
while ((chunk = stream.Read(buffer, read, buffer.Length - read)) > 0) // After 2 attempts it hangs here
{
read += chunk;
/* If we've reached the end of our buffer, check to see if there's
any more information */
if (read == buffer.Length)
{
int nextByte = stream.ReadByte();
/* End of stream? If so, we're done */
if (nextByte == -1)
{
return buffer;
}
/* Nope. Resize the buffer, put in the byte we've just
read, and continue */
byte[] newBuffer = new byte[buffer.Length * 2];
Array.Copy(buffer, newBuffer, buffer.Length);
newBuffer[read] = (byte)nextByte;
buffer = newBuffer;
read++;
}
}
/* Buffer is now too big. Shrink it. */
byte[] ret = new byte[read];
Array.Copy(buffer, ret, read);
return ret;
}