Hi,
I have a problem with HttpWebRequest. I’m trying to get JSON data from local network server but I’ve get only partial of data (usually first 1069-1070 bytes).
I’m using FezPortal for that projec, and my GET is implemented as below
private byte[] GetResult = new byte[4 * 1024];
public string Get(string url)
{
int read = 0, total = 0;
byte[] result = GetResult;
try
{
HttpWebRequest.Create(url);
using (var req = HttpWebRequest.Create(url) as HttpWebRequest)
{
req.KeepAlive = true;
req.ReadWriteTimeout = 10000;
req.Timeout = 10000;
Thread.Sleep(500);
using (var res = req.GetResponse() as HttpWebResponse)
{
using (var stream = res.GetResponseStream())
{
do
{
Thread.Sleep(500);
read = stream.Read(result, total, result.Length-total);
total += read;
}
while (read != 0);
}
}
String page = "";
page = new String(System.Text.Encoding.UTF8.GetChars(result, 0, total));
return page;
}
}
catch (Exception e)
{
}
return null;
}
}
BR
KJ