Netty 消息中断

Netty message cut off

我有一个 java http 服务器,它使用 Netty 4.0.39

当我在 HttpResponse 中发送一个大字符串时,C# 客户端只收到发送数据的四分之一。

java中发送数据的方法是

    FullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status);
    response.headers().set(HttpHeaders.Names.ACCEPT_ENCODING, HttpHeaders.Values.GZIP);
    response.headers().set(HttpHeaders.Names.CONTENT_TYPE, "application/octet-stream; charset=UTF-8");
    response.headers().set(HttpHeaders.Names.CONTENT_LENGTH, finalEncoded.length());
    response.content().writeBytes(Unpooled.copiedBuffer(finalEncoded, CharsetUtil.UTF_8));
    channel.writeAndFlush(response);

我所说的大小最大为 1000000 字节。 大多数时候消息总是在同一个点被截断

编辑:

读取消息的 C# 代码

private byte[] makeRequest(byte[] data, int timeout = 0) 
{ 
     WebRequest req = WebRequest.Create(uri); 
     req.Method = "POST"; 
     ((HttpWebRequest)req).ProtocolVersion = HttpVersion.Version11; 
     if (UseProxy && webProxy != null) 
     { 
        req.Proxy = webProxy; 
        req.PreAuthenticate = false; 
        //req.UseDefaultCredentials = false; 
     } 
     req.ContentLength = data.Length; 
     if (timeout > 0) 
     { 
        req.Timeout = timeout; 
     } 
     using (var stream = req.GetRequestStream()) 
     { 
        stream.Write(data, 0, data.Length); 
        stream.Close(); 
     } 
     lock (requestsLock) 
     { 
        openWebRequests.Add(req); 
     } 
     byte[] responseBytes = null; 
     try 
     { 
        using (var response = req.GetResponse()) 
        { 
            if (response == null) return null; 
            responseBytes = ReadFully(response.GetResponseStream()); 
        } 
      } 
      catch (Exception e) 
      { 
        Log(MessagingTypes.ProtocolLevels.Exceptions, e.Message); 
        return null; 
      } 
      return responseBytes; 
} 


private byte[] ReadFully(Stream input)
{
     using (MemoryStream ms = new MemoryStream())
     {
             input.CopyTo(ms);
             return ms.ToArray();
     }
}

我们最终将包作为 HttpChunks 发送。之后一切正常。