友人が C# で HTTP POST を実装するこのサンプル コードを見せてくれ、 WINFORMアプリでうまくいきました 。 request-with-c/
そしてMETRO APPに実装されています:
// this is what we are sending
string post_data = "user=user@example.com&pass=example123";
// this is where we will send it
string uri = "http://app.proceso.com.mx/win8/login";
// create a request
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri);
request.Method = "POST";
// turn our request string into a byte stream
byte[] postBytes = Encoding.UTF8.GetBytes(post_data);
// this is important - make sure you specify type this way
request.ContentType = "application/x-www-form-urlencoded";
Stream requestStream = await request.GetRequestStreamAsync();
// now send it
requestStream.Write(postBytes, 0, postBytes.Length);
// grab te response and print it out to the console along with the status code
WebResponse response = await request.GetResponseAsync();
//var a = new StreamReader(response.GetResponseStream()).ReadToEnd();
StreamReader requestReader = new StreamReader(response.GetResponseStream());
String webResponse = requestReader.ReadToEnd();
HttpWebRequest には ProtocolVersion が含まれておらず、次の行にこのエラーがスローされていることに気付きました。
WebResponse response = await request.GetResponseAsync();
// ERROR: The remote server returned an error: (417) Expectation Failed.
最後のプロパティが解決策だと思います。どうすればこの問題を解決できますか? 前もって感謝します