IE アドオンを開発していますが、問題が発生しました。私はグーグルをたくさんサーフィンしましたが、解決策は見つかりませんでした。問題は、C# アドオンから別のサーバーにポスト httpwebrequest を送信し、そのサーバーからの応答を取得していることです。単一のフォームから複数のリクエストを送信したいと考えています。送信している最初のリクエストは正常に機能していますが、2 番目のボタンを押して 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);
誰でもこの問題について私を助けてくれませんか。
前もって感謝します。