S
Stig-Arne Basberg
I am working on a project where I want to send at file from a Win CE device
to a receiving PC using the HTTP protocol.
For testing purpose I made a simple test app on my PC (code below).
The problem is that only the first 8760 bytes of the file is transfered. I
have tried several times and the received file is always 8760 bytes.
I have tested with several files (10k -> 200k).
My receiving application works very well with other application. I have
transfered files over 1MB. So there must be something with my send
application.
I have checked that the size in the header message is received correctly at
the receiving end but the actual stream is to short. The size of the stream
buffer on the sending side is also correct. So it seems like there is some
problems with the "low level" transfer. Is there some setting I may have
missed?
Does someone have any ideas?
Thanks in advance for any comments
public void SendFile()
{
try
{
HttpWebRequest request=(HttpWebRequest)
WebRequest.Create("http://192.168.1.10:16000/Send/test.xml);
request.ContentType="text/xml";
request.Method = "POST";
request.Timeout = 10000;
FileStream fs = new FileStream("D:\\Temp\\test.xml", FileMode.Open,
FileAccess.Read);
request.ContentLength = fs.Length;
fs.Close();
request.AllowWriteStreamBuffering = true;
request.BeginGetRequestStream(new AsyncCallback(ReadCallback),
request);
allDone.WaitOne();
HttpWebResponse httpWResp = (HttpWebResponse)request.GetResponse();
httpWResp.Close();
}
catch (System.Net.WebException escWeb)
{
if (escWeb.Response != null)
escWeb.Response.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}//------------------------------------------------------------------------
private static void ReadCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request =
(HttpWebRequest)asynchronousResult.AsyncState;
request.AllowWriteStreamBuffering = true;
Stream postStream = request.EndGetRequestStream(asynchronousResult);
FileStream fs = new FileStream("D:\\temp\\test.xml", FileMode.Open,
FileAccess.Read, FileShare.None);
byte[] buf = new byte[fs.Length];
fs.Read(buf, 0, (int)fs.Length);
postStream.Write(buf, 0, buf.Length);
postStream.Close();
fs.Close();
allDone.Set();
}
catch (System.Net.WebException escWeb)
{
if (escWeb.Response != null)
escWeb.Response.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}//------------------------------------------------------------------------
to a receiving PC using the HTTP protocol.
For testing purpose I made a simple test app on my PC (code below).
The problem is that only the first 8760 bytes of the file is transfered. I
have tried several times and the received file is always 8760 bytes.
I have tested with several files (10k -> 200k).
My receiving application works very well with other application. I have
transfered files over 1MB. So there must be something with my send
application.
I have checked that the size in the header message is received correctly at
the receiving end but the actual stream is to short. The size of the stream
buffer on the sending side is also correct. So it seems like there is some
problems with the "low level" transfer. Is there some setting I may have
missed?
Does someone have any ideas?
Thanks in advance for any comments
public void SendFile()
{
try
{
HttpWebRequest request=(HttpWebRequest)
WebRequest.Create("http://192.168.1.10:16000/Send/test.xml);
request.ContentType="text/xml";
request.Method = "POST";
request.Timeout = 10000;
FileStream fs = new FileStream("D:\\Temp\\test.xml", FileMode.Open,
FileAccess.Read);
request.ContentLength = fs.Length;
fs.Close();
request.AllowWriteStreamBuffering = true;
request.BeginGetRequestStream(new AsyncCallback(ReadCallback),
request);
allDone.WaitOne();
HttpWebResponse httpWResp = (HttpWebResponse)request.GetResponse();
httpWResp.Close();
}
catch (System.Net.WebException escWeb)
{
if (escWeb.Response != null)
escWeb.Response.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}//------------------------------------------------------------------------
private static void ReadCallback(IAsyncResult asynchronousResult)
{
try
{
HttpWebRequest request =
(HttpWebRequest)asynchronousResult.AsyncState;
request.AllowWriteStreamBuffering = true;
Stream postStream = request.EndGetRequestStream(asynchronousResult);
FileStream fs = new FileStream("D:\\temp\\test.xml", FileMode.Open,
FileAccess.Read, FileShare.None);
byte[] buf = new byte[fs.Length];
fs.Read(buf, 0, (int)fs.Length);
postStream.Write(buf, 0, buf.Length);
postStream.Close();
fs.Close();
allDone.Set();
}
catch (System.Net.WebException escWeb)
{
if (escWeb.Response != null)
escWeb.Response.Close();
}
catch (Exception e)
{
MessageBox.Show(e.ToString());
}
}//------------------------------------------------------------------------