Сначала проверьте это сообщение, которое я пытался сделать:

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

Вот тестовая учетная запись:

  • Пользователь: javier.lopez.contreras10@gmail.com
  • Пройдено: policarpio20

Итак, если вы установите данные на этой странице: http://app.proceso.com.mx/ win8 / login_test вы получите хэш-код.

И это то, чего я пытаюсь достичь в приложении для метро, ​​но я чувствую себя потерянным в этой ситуации. Я понятия не имею, отправлять эти данные для получения хэш-кода. Я использовал HttpClient и HttpContent, но не уверен.

Заранее спасибо.

ОБНОВЛЕНИЕ: Спасибо dharnitski за код, прямо сейчас я модифицирую этот код для Win8 CP:

        // this is what we are sending
        string post_data = "user=javier.lopez.contreras10@gmail.com&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.

Как я могу решить эту проблему, если я могу изменить версию протокола?

2
Darf Zon 11 Июн 2012 в 05:31

1 ответ

Лучший ответ

Это пример кода для реализации HTTP POST на C #.

http://www.terminally-incoherent.com/blog/2008/05/05/send-a-https-post-request-with-c/

ВАЖНО: вы должны переключить свою веб-страницу на HTTPS (SSL). Отправлять незашифрованные пароли - это очень плохая практика.

2
Dmitry Harnitski 11 Июн 2012 в 05:58
Большое спасибо, ваша страница со ссылками получилась! Пожалуйста, проверьте мое обновление
 – 
Darf Zon
11 Июн 2012 в 08:16