2

まず、私がやろうとしていたこのメッセージを確認してください:

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

テスト アカウントは次のとおりです。

  • ユーザー: javaer.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.

プロトコルのバージョンを変更できる場合、この問題をどのように解決できますか?

4

1 に答える 1

2

これは、C# で HTTP POST を実装するサンプル コードです。

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

重要: Web ページを HTTPS (SSL) に切り替える必要があります。暗号化されていないパスワードを送信することは、非常に悪い習慣です。

于 2012-06-11T01:58:17.873 に答える