I am developing IE addon and now a problem occurred. I surfed the google alot but no solution i found. The problem is i am sending a post httpwebrequest from my C# addon to another server and getting the response from that server. now i want to send more than one requests from single form. the first request i am sending is working well but when i press the second button to send httpwebrequest again, it gives me the error.
Here is my code :
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;
}
Calling the method :
string url ="abc.com/abc_controller/abc_function"; // Codeigniter Website url
string data = "fn_name=TEMP&city=Delhi";
abctextbox.Text = postdata(url, data);
Can anyone please help me on this issue.
Thanks in advance.