我正在开发IE插件,现在出现了问题。我浏览谷歌很多但没有找到解决方案。问题是我从我的C#addon发送一个帖子httpwebrequest到另一台服务器并从该服务器获取响应。现在我想从单个表单发送多个请求。我发送的第一个请求运行正常但是当我按第二个按钮再次发送httpwebrequest时,它给了我错误。
这是我的代码:
public string postdata(string url, string data)
{
string result = null;
// Create the web request
HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest;
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
using (Stream s = request.GetRequestStream())
{
using (StreamWriter sw = new StreamWriter(s))
sw.Write(data);
}
// Get response
using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)
{
// Get the response stream
StreamReader reader = new StreamReader(response.GetResponseStream(), Encoding.UTF8);
// Read the whole contents and return as a string
result = reader.ReadToEnd();
}
return result;
}
调用方法:
string url ="abc.com/abc_controller/abc_function"; // Codeigniter Website url
string data = "fn_name=TEMP&city=Delhi";
abctextbox.Text = postdata(url, data);
任何人都可以帮我解决这个问题。
提前致谢。