发布登录时出现 Web 客户端错误 417
本文关键字:Web 客户端 错误 布登录 登录 | 更新日期: 2023-09-27 18:35:20
>我一直在尝试使用WebClient为登录表单发布数据,但是无论我做什么,我都会返回417 Expect错误。我尝试了"ServicePointManager.Expect100Continue = false;",但它没有做任何事情。我开始怀疑这可能是我的代码中的错误,但我无法说出它是什么。
public void initiateCredits(string user, string pass)
{
System.Net.WebClient wc2 = new System.Net.WebClient();
string webData = wc2.DownloadString("http://localhost");
Regex check = new Regex("(?<=You have)(.*)(?=credits)", RegexOptions.Singleline);
bool checkmatch = check.IsMatch(webData);
if (checkmatch == true)
{
return;
}
else
{
ServicePointManager.Expect100Continue = false;
DisableClickSounds();
string url = "http://localhost";
string pass_d = Base64.decode(pass);
string postData = String.Format("username=" + user + "&password=" + pass_d);
byte[] Post = Encoding.UTF8.GetBytes(postData);
WebClient wc = new WebClient();
byte[] response = wc.UploadValues(url, new NameValueCollection()
{
{ "username", user },
{ "password", pass_d }
});
creditlogin = true;
//string AdditionalHeaders = "Content-Type: application/x-www-form-urlencoded";
//wb.Navigate(url, null, Post, AdditionalHeaders);
}
有没有人知道为什么我似乎无法删除这些标头,或者为什么我会收到此错误?谢谢!
将此行添加到您的应用程序配置文件配置部分 - 在我的情况下,只有这会阻止发送"Expect:"标头:
<system.net>
<settings>
<servicePointManager expect100Continue="false" />
</settings>
</system.net>