C# 发布登录时出现WebClient错误417

C# 发布登录时出现WebClient错误417,c#,C#,我一直在尝试使用WebClient发布登录表单的数据,但是无论我做什么,我都会收到一个417 Expect错误。我尝试了“ServicePointManager.Expect100Continue=false”;但它什么也没做。我开始怀疑这可能是我的代码中的一个错误,但我不知道它是什么 public void initiateCredits(string user, string pass) { System.Net.WebClient wc2 = new Sys

我一直在尝试使用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);
        }
public void initiateCredits(字符串用户,字符串传递)
{
System.Net.WebClient wc2=新系统.Net.WebClient();
字符串webData=wc2。下载字符串(“http://localhost");

Regex check=new Regex(“(?将此行添加到您的应用程序配置文件配置部分-在我的情况下,只有这样才能防止发送“Expect:”头:



尝试使用查看线路上发生了什么。服务器的响应中是否有
Expect
头字段?有时需要它们进行某种身份验证。但是,请查看如何处理本地主机,如果使用它,我让fiddler工作,是的,无论我设置了什么,它仍然发送Expect头”ServicePointManager.Expect100Continue“到。并且,为了确保,标题字段的值是
100 continue
?我得到的响应标题是
HTTP/1.1417 Expection失败
,传输显示
Expect100 continue
<system.net>
    <settings>
        <servicePointManager expect100Continue="false" />
    </settings>
</system.net>