0
リモートWebサイトには、フォームに入力値を入力したり、ボタンをクリックしたり、出力フォームで結果を取得できるページがあります。 必要な入力フォームを記入してページにリクエストを送信し、それを送信し、出力フォームが記入された結果ページを取得したいと考えています。類似したトピックについてcsharpで送信した後に応答ページを取得するには?
すべてのスレッドは、このようなコードサンプルを与える:
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create("http://www.site.com");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = string.Format("inputParam=value");
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
WebResponse response = request.GetResponse();
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream();
response.Close();
は、それが満たされた入力フォームにページを返しますが、それはボタンのクリックをコミットしませんように、出力フィールドは、まだ空白になっています。
C#コードからコミットを行い、出力データを含むhtml文書を受け取るにはどうすればよいですか?
いいえ、ストリームから文字列があります。しかし問題は、応答に出力データが含まれていないことです。 – Sindoki
期待される応答は何ですか? – daryal
サイトのURLは「http://babelfish.yahoo.com/translate_txt」です。パラメータの例は、 "lp = en_it&trtext = sea"です。レスポンス・ページでは、name = "p"の要素はvalue = "mare"でなければなりませんが、空白です。 – Sindoki