【发布时间】:2020-02-18 20:26:11
【问题描述】:
我现在有一个使用此布局的 HTTP POST 请求:
private static readonly HttpClient client = new HttpClient();
var values = new Dictionary<string, string>
{
{ "thing1", "hello" },
{ "thing2", "world" }
};
var content = new FormUrlEncodedContent(values);
var response = await client.PostAsync("https://www.example.com/recepticle.aspx", content); //It's not the URL I'm using.
var responseString = await response.Content.ReadAsStringAsync();
我想使用 C# 的 POST 请求在网站上设置密码(文本框)。我尝试使用上述布局,但没有设置它。所以我认为这是因为我使用的是 HTTP 请求而不是 HTTPS 请求(你认为我是对的吗?)。我的问题是,我不知道如何将其作为 HTTPS 请求发送。我需要一种方法使它成为 HTTPS。
我应该澄清一下,我要发送以下内容:
Password, - Not in the textbox
Password again, - Not in the textbox
question index, - In the textbox
answer for the question, - In the textbox
terms_of_service. - Not in the textbox
所以我猜该网站确实处理了我的请求,但并不关心其中的某些内容。也许是饼干?
提前谢谢你。
【问题讨论】:
-
只需在
http之后添加一个s,HttpClient 将负责其余的工作。 -
@WashingtonA.Ramos 对不起,我正在使用的 URL 确实以 HTTPS 开头,我在代码中确实提到了它。还是不行。
-
响应的状态码和响应内容是什么?
-
这不太可能与 HTTPS 有关。如果您尝试 POST 到 WebForms 页面(假设来自 .aspx),则需要包含有效的 __VIEWSTATE 和 __EVENTVALIDATION 值,通常从 GET 获得。可能还需要 CSRF 令牌。然后,您需要将回发的控制源设置为正常登录按钮的正确唯一标识符,并将用户名和密码作为用户名和密码文本框的唯一标识符的值发送。
-
这能回答你的问题吗? Make Https call using HttpClient
标签: c# ssl https httpclient