私はこれを自分で理解しようとしましたが、有用な解決策が得られません。Web サイトにリクエストを送信し、処理された結果を取得したいと考えています。私はすでにこれに問題を抱えていました ( How do I fill in a website form and retrieve the result in C#? を参照してください) が、そこに記載されている Web サイトで解決できました。次のコードを使用して、さらに別の Web サイト ( http://motif-x.med.harvard.edu/motif-x.html )にアクセスしようとしています。
ServicePointManager.Expect100Continue = false;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://motif-x.med.harvard.edu/cgi-bin/multimotif-x.pl");
request.Credentials = CredentialCache.DefaultCredentials;
request.ProtocolVersion = HttpVersion.Version10; // Motif-X uses HTTP 1.0
request.KeepAlive = false;
request.Method = "POST";
string motives = "SGSLDSELSVSPKRNSISRTH";
string postData = "fgdata=" + motives + "&fgcentralres=S&width=21";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
request.ContentType = "multipart/form-data";
request.ContentLength = byteArray.Length;
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
これにより、次の例外が発生します。
リモート サーバーがエラーを返しました: (500) 内部サーバー エラー。
これを防ぐためにできることはありますか?
サイトに手動で入力する場合:
データセットのテキストエリア:SGSLDSELSVSPKRNSISRTH
中心人物(基本オプション):S
結果のサイトにリダイレクトされますが、処理に時間がかかる場合があります。それが実際に例外の理由になるのでしょうか?