次のユースケースで不可解な状況があります。
- ApacheサーバーへのSSLを使用したユーザーログイン
- Apache 返送 ->
- header("Context-Type: プレーン/テキスト");
- echo "リクエストを送信";
- ユーザーは、データの httpwebrequest を使用して c#/.net から新しい要求を送信します
- Apacheはjsonでデータを送り返します
- 必要なデータを持っているユーザーであり、続行しても問題ありません
上記のシナリオを c#/form.timer; に入れました。ほとんどの場合、ノイズなしでバックグラウンドで必要に応じてスムーズに実行されます。ただし、しばらくすると (通常は数時間)、手順 3) が失敗し、常にログイン ページ (http ステータス 302) にリダイレクトされます。
Apache サーバーと php はかなり古くなっています (Apache 2.2.10 と php 5.2.xx)。
C# では、httpwebrequest には以下のコード スニペットに示す設定があります。
System.Net.ServicePointManager.Expect100Continue = false;
lrequest = (HttpWebRequest)WebRequest.Create(tmp_url);
lrequest.CookieContainer = ThisAddIn.getCookieContainer();
lrequest.KeepAlive = true;
lrequest.AllowAutoRedirect = false;
lrequest.Method = "POST";
lrequest.ContentType = "application/x-www-form-urlencoded";
lrequest.UserAgent = "Mozilla/4.0 (compatible; MSIE 9.0; MSIE 8.0; MSIE 7.0; Windows NT 6.1; WOW64; Trident/4.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; Media Center PC 6.0; MAAU; InfoPath.2; .NET CLR 1.1.4322; MS-RTC LM 8; .NET4.0C; .NET4.0E; OfficeLiveConnector.1.5; OfficeLivePatch.1.3)";
int tmp_len = dbyte.Length;
lrequest.ContentLength = tmp_len;
Stream dstream = lrequest.GetRequestStream();
dstream.Write = (dbyte,0,tmp_len);
dstream.Close();
lresponse = (HttpWebResponse)lrequest.GetResponse();
dstream = lresponse.GetResponseStream();
reader = new StreamReader(dstream);
rdata = reader.ReadToEnd();
reader.Close();
dstream.Close();
lresponse.Close();