日期:2014-05-20  浏览次数:20823 次

HttpWebRequest发送post请求问题
HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
                //请求方式
                request.Method = "POST";
                //超时时间
                //request.Timeout = 300000;
                request.ContentType = "text/xml";
                byte[] payload = Encoding.UTF8.GetBytes(message);
                request.ContentLength = payload.Length;
                //获得请求流
                writer = request.GetRequestStream();
                ////将请求参数写入流
                writer.Write(payload, 0, payload.Length);

                //关闭请求流
                writer.Flush();
                writer.Close();

                reader = new StreamReader(response.GetResponseStream());
                string responseData = reader.ReadToEnd();
                response.Close();
                reader.Close();

代码如上所示,当我循环执行多次这个代码时,导致连接无法释放
查看端口效果如下:

求大神指教啊,急啊,当什么都不发的时候,循环多次没有任何问题

------解决方案--------------------
response 那里冒出来的?你的代码完整
------解决方案--------------------
引用:
HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
                //请求方式
                request.Method = "POST";
                //超时时间
                //request.Timeout = 300000;
                request.ContentType = "text/xml";
                byte[] payload = Encoding.UTF8.GetBytes(message);
                request.ContentLength = payload.Length;
                //获得请求流
                writer = request.GetRequestStream();
                ////将请求参数写入流
                writer.Write(payload, 0, payload.Length);

                //关闭请求流
                writer.Flush();
                writer.Close();

                reader = new StreamReader(response.GetResponseStream());
                string responseData = reader.ReadToEnd();
                response.Close();