gpt4 book ai didi

c# - 如何使用方法 post 使用 HttpRequest 发送变量?

转载 作者:太空宇宙 更新时间:2023-11-03 11:21:07 24 4
gpt4 key购买 nike

首先,检查我正在尝试执行的这条消息:

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您将收到一个哈希码。

这就是我试图在 Metro 应用程序中实现的目标,但我感到迷失在这种情况下。我不知道发送这些数据来接收哈希码。我使用的是 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.

如果可以修改协议(protocol)版本,如何解决这个问题?

最佳答案

这是在 C# 中实现 HTTP POST 的示例代码

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

重要提示:您必须将网页切换为 HTTPS (SSL)。发送未加密的密码是非常糟糕的做法。

关于c# - 如何使用方法 post 使用 HttpRequest 发送变量?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10973734/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com