我一直在尝试使用 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);
}
有谁知道为什么我似乎无法删除这些标题,或者为什么我收到此错误?谢谢!