错误:提交请求后无法执行此操作 [英] Error: This Operation cannot be performed after request has been submitted

查看:1825
本文介绍了错误:提交请求后无法执行此操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写了关于 httpwebrequest httpwebresponse 的代码。我需要将数据发送到服务器但得到此异常在提交请求后无法执行此操作。请参阅以下代码:

I've written code about httpwebrequest and httpwebresponse . I need to send data to server but got this exception "This operation cannot be performed after request has been submitted". see the following code:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://"+remoteServer+":8080/");
request.Credentials = CredentialCache.DefaultCredentials;
//Stream NewReqstream = request.GetRequestStream();
request.Method = "POST";
//request.ContentLength = cmd.Length;
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine("Connected..");

// Send the command
//clientSocket.Send(cmd);

Stream NewReqstream = request.GetRequestStream(); //<-- Error here
NewReqstream.Write(cmd, 0, cmd.Length);
NewReqstream.Close();


推荐答案

当您收到响应流时,请求已提交你不能在那里操作......

when you get the response stream the request is submitted so you can not the operation there...

试试看:

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://"+remoteServer+":8080/");
request.Credentials = CredentialCache.DefaultCredentials;
//Stream NewReqstream = request.GetRequestStream();
request.Method = "POST";
//request.ContentLength = cmd.Length;

// Send the command
//clientSocket.Send(cmd);

Stream NewReqstream = request.GetRequestStream(); //<-- Error here
NewReqstream.Write(cmd, 0, cmd.Length);
NewReqstream.Close();

// Get the response
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine("Connected..");

这篇关于错误:提交请求后无法执行此操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆