C# WebClient.UploadData出现问题

C# WebClient.UploadData出现问题,c#,webclient.uploaddata,C#,Webclient.uploaddata,我有一个客户端-服务器类型的应用程序,服务器运行HttpListener,客户端使用WebClient.UploadData将数据上传到服务器。除了一个安装,当数据缓冲区大小大于16384时,UploadData会超时外,该代码在大数据缓冲区为60K及以上时运行良好。以下是我在客户机上的代码: internal bool UploadData(byte[] buffer, String file, String folder) { try { String uri

我有一个客户端-服务器类型的应用程序,服务器运行HttpListener,客户端使用WebClient.UploadData将数据上传到服务器。除了一个安装,当数据缓冲区大小大于16384时,UploadData会超时外,该代码在大数据缓冲区为60K及以上时运行良好。以下是我在客户机上的代码:

internal bool UploadData(byte[] buffer, String file, String folder)
{
    try
    {
        String uri = "http://" + GlobalData.ServerIP + ":" + GlobalData.ServerHttpPort + "/upload:";
        NameValueCollection headers = new NameValueCollection();
        headers.Set("Content-Type", "application/octet-stream");
        headers.Set("Y-Folder", folder);
        headers.Set("Y-File", file);
        using (WebClient wc = new WebClient())
        {
            wc.Credentials = new NetworkCredential(WebUserName, WebPassword);
            wc.Headers.Add(headers);
            wc.UploadData(new Uri(uri), buffer);
            return true;
        }
    }
        catch (Exception ex)
        {
            GlobalData.ODS("Exception in UploadFile " + ex.Message);
            return false;
        }
    }
在服务器上

ODS(TraceDetailLevel.Level4, "Process upload ");
HttpListenerResponse response = e.RequestContext.Response;
String disp = "";
String fil = "";
String folder = "";
Stream body = e.RequestContext.Request.InputStream;
long len64 = e.RequestContext.Request.ContentLength64;
Encoding encoding = e.RequestContext.Request.ContentEncoding;
ODS(TraceDetailLevel.Level4, "Process upload " + len64 + " bytes encoding " + encoding.EncodingName);
NameValueCollection nvp = e.RequestContext.Request.Headers;
try
{
disp = nvp["Content-Disposition"];
fil = nvp["Y-File"];
folder = nvp["Y-Folder"];
}
catch { }
BinaryReader reader = new BinaryReader(body, encoding);
byte[] data = new byte[len64];
long total = 0;
while (true)
{
  int dataleft = data.Length - (int)total;
  int offset = (int)total;
  GlobalData.ODS("Reading binary stream offset=" + offset + " read dataleft=" + dataleft);
  int cnt = reader.Read(data, offset, dataleft);
  if (cnt <= 0)
  {
    break;
  }
  total += cnt;
  if (len64 <= total)
  {
    break;
  }
}
ODS(TraceDetailLevel.Level4, "Process upload: Got  data "+total+" should have="+len64);
if (total == len64)
{
  //process data

上述代码在除一个安装外的所有安装上都能正常工作。怎么了

看来我找到了问题的根源。这个有问题的安装没有通过我的代码,在运行我的HTTP服务器代码的计算机上安装了AVG免费防病毒软件。如果我在那台计算机上禁用AVG,我的代码就可以工作。想知道是否有人在AVG上遇到类似问题。

想补充一点,代码在LAN上运行,即使客户端和服务器在同一台机器上运行,也会出现超时