アプリのPOSTリクエストをいくつかのURLに送信します。初めて送信するときは問題ありませんが、もう一度メソッドを呼び出すとSendBookingFreeCapacity()
、
ApplicationUnhandledExceptionEventArgs
App.xamlの関数で"private void Application_UnhandledException(object sender, ApplicationUnhandledExceptionEventArgs e)"
。
問題はラインです:
webRequest.BeginGetResponse(new AsyncCallback(GetBookingFreeCapacitydResponseCallback), webRequest);
これが私のコードです:
public static void SendBookingFreeCapacity() {
var url = "https://..../getFreeCapacity";
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url);
webRequest.Method = "POST";
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.BeginGetRequestStream(
new AsyncCallback(GetBookingFreeCapacityRequestStreamCallback),
webRequest);
}
private static void GetBookingFreeCapacityRequestStreamCallback(
IAsyncResult asynchronousResult)
{
try {
HttpWebRequest webRequest =
(HttpWebRequest)asynchronousResult.AsyncState;
string postData = string.Empty;
System.IO.Stream postStream =
webRequest.EndGetRequestStream(asynchronousResult);
postData = "<?xml version=\"1.0\"?>"
+ "<request>"
+ "<login>" + Globals.Login + "</login>"
+ "<password>" + Globals.Password + "</password>"
+ "<hotId>" + htl.hotId + "</hotId>"
+ "<term>"
+ "<from>" + dayParser(Globals.PrijezdDate) + "</from>"
+ "<to>" + dayParser(Globals.OdjezdDate) + "</to>"
+ "</term>"
+ "</request>";
byte[] byteArray = System.Text.Encoding.UTF8.GetBytes(postData);
postStream.Write(byteArray, 0, byteArray.Length);
postStream.Close();
webRequest.BeginGetResponse(
new AsyncCallback(GetBookingFreeCapacitydResponseCallback),
webRequest); //after this I get the exception
}
catch (Exception ex) { }
}
private static void GetBookingFreeCapacitydResponseCallback(
IAsyncResult asynchronousResult)
{
try {
HttpWebRequest webRequest =
(HttpWebRequest)asynchronousResult.AsyncState;
//some code...
}
catch (Exception ex) { }
}
それを引き起こす可能性のあるヒントはありますか?問題はどこにありますか?