http服务端返回数据有多余内容问题

我用httplistenter做了一个http的服务端,接受一个远程设备发送的数据,并根据结果给其返回相应数据。返回数据代码如下:
HttpListenerContext ctx = httpListener.GetContext();
string result = "+IPDA3810DE1F4E7D";
byte[] buffer = Encoding.ASCII.GetBytes(result);
ms.Write(buffer, 0, buffer.Length);

        ms.Flush(); ms.Close();
        ctx.Response.Close();
                    但是远程设备接收到的数据会在返回的result字符的前面和后面会有其他的字符和换行存在。这应该是哪里产生的问题呢?

Write前clear下输出缓存试试

 ctx.Response.Clear();
ms.Write(buffer, 0, buffer.Length);

ctx.response继承的是 HttpListenerResponse这个类没有clear方法的,应该怎么弄呢?