0
원격 웹 사이트에 페이지가있어 양식에 입력 값을 입력하고 버튼을 클릭하여 출력 양식으로 결과를 얻을 수 있습니다. 필요한 입력 양식을 작성하여 페이지에 요청을 보내고 제출하고 출력 양식이 채워진 결과 페이지를 가져오고 싶습니다. 비슷한 주제와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