2012-06-11 43 views
2

首先檢查這個消息,我要怎樣做:如何使用HttpRequest方法post發送變量?

Login 

To log on to Windows8 service is through the URL: http://app.proceso.com.mx/win8/login 

This URL HTTP Request Method receives POST variables user and pass. The variable user is the user's email and pass the variable is the same password. In the event that the user or password are invalid return plain text number zero 0, in the opposite case, that the username and password are valid return plain text an alphanumeric string of 32 characters, as this b17f27a16589fee247c666da6ed15569, this string is the hash of the valid user valid and will run from 00:00 hours to 23:59 hours the day it was generated. 

To test the URL was created: http://app.proceso.com.mx/win8/login_test 

Note: It should be clear that the hash generated will only be valid for Windows8 service to the user that gender and the effect from 00:00 hours to 23:59 on the day it was generated. 

Note: All services generate text in UTF-8 

下面是測試賬戶:

所以,如果你設置的數據在本頁面:http://app.proceso.com.mx/win8/login_test您將收到一個哈希碼。

而這正是我想要在地鐵應用程序中完成的,但我感覺在這種情況下感到迷茫。我不知道發送這些數據來接收哈希碼。我使用HttpClient和HttpContent,但我不確定。

在此先感謝。

UPDATE:感謝dharnitski的代碼,我現在正在修改適用於Win8 CP驗證碼:

 // this is what we are sending 
     string post_data = "[email protected]&pass=policarpio20"; 

     // 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. 

如果我可以修改協議版本,該如何解決此問題?

回答