C# - Web客户端发布数据(C# - Webclient Post Data)

2019-10-17 12:36发布

我试着去这里复制站点后: https://www.usbank.com/cgi_w/cfm/personal/products_and_services/reoPropertiesReq.cfm

我只是想张贴任何国家看到的结果,因为他们将在一封电子邮件中结束。 这是我的post方法,它适用于在其他网站登录等,所以我知道它的工作原理

public HtmlDocument POST(string url, string postData)
    {//string myParameters = "param1=value1&param2=value2&param3=value3";

        HtmlDocument hdoc = new HtmlDocument();
        wc.Headers[HttpRequestHeader.ContentType] = "application/x-www-form-urlencoded";
        using (wc)
        {
            hdoc.LoadHtml(wc.UploadString(url, postData));
        }

        return hdoc;
    }

我使用它像:

HtmlDocument mainDoc = POST("https://www.usbank.com/cgi_w/cfm/personal/products_and_services/reoPropertiesReq.cfm",
            "selState=4&StateNM=Arizona");

但是这似乎不正确。 任何人都可以分析该网站,并确定如果我的代码或丢失的数据?

Answer 1:

我写这个功能对我前一段时间,希望这有助于

    private void POST(string url, string data)
    {
        HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(new Uri(url));
        req.Method = "POST";
        req.Headers.Add(HttpRequestHeader.AcceptLanguage, "de-DE,de;q=0.8,en-US;q=0.7,en;q=0.3");

        req.Timeout = req.ReadWriteTimeout = 15000;

        ASCIIEncoding encoding = new ASCIIEncoding();
        byte[] dataBytes = encoding.GetBytes(data);
        req.ContentLength = dataBytes.Length;
        Stream stream = req.GetRequestStream();
        stream.Write(dataBytes, 0, dataBytes.Length);
        stream.Close();

        req.GetResponse();
    }


文章来源: C# - Webclient Post Data