C# - 来自复选框的HTTP POST请求

时间:2016-06-30 10:40:21

标签: c# wpf http post checkbox

尝试编写一个c#app来注册所有these newsletters,我使用HTTPFox分析HTTP请求并构造正确的POST参数,但WebRequest正在抛出403禁止。我用简单的形式成功完成了这项工作,但是大量的控制器和复选框很重。

HTTPFox输出:

POST数据:

Parameter: Value
    _account_id 737
    _table_id   1
    _email_field    1.email
    _dedupe 1
    _static_update  1
    _rp https://www.insidermedia.com/newsletter/subscription-successful
    _list_id    12
    _list_id    1
    _list_id    8
    _list_id    5
    _list_id    4
    _list_id    10
    _list_id    14
    _list_id    6
    _list_id    13
    _list_id    2035
    _list_id    7091
    _list_id    318
    _list_id    2
    _list_id    7294
    _list_id    317
    _list_id    8702
    _list_id    7298
    _list_id    7295
    _list_id    7297
    _list_id    10158
    _list_id    6419
    7.title Mr
    7.first_name    fname_redacted
    7.surname   sname_redacted
    1.email redactedg@outlook.com
    7.company   cname_redacted
    7.position  Analyst
    7.add1  23 liverpool road
    7.add2  
    7.add3  
    7.add4  liverpool
    7.add5  Bedfordshire
    7.postcode  l59uh
    7.telephone 1519838474
    7.sector    Accountants
    7_employees Less than 25
    7.turnover  
    7.registered_by 
    7.audit_question    

接头:

Request_header: Value
(Request-Line)  POST /s/ HTTP/1.1
Host    newsco.msgfocus.com
User-Agent  Mozilla/5.0 (Windows NT 6.3; WOW64; rv:47.0) Gecko/20100101 Firefox/47.0
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-US,en;q=0.5
Accept-Encoding gzip, deflate, br
Referer https://www.insidermedia.com/newsletter/adestra/216611
Connection  keep-alive
Content-Type    application/x-www-form-urlencoded
Content-Length  752

C#:

    WebRequest request = WebRequest.Create("https://www.insidermedia.com/newsletter/subscribe");
    request.Method = "POST";
    string postData = "email=redacted%40outlook.com";
    postData += "&_account_id=737";
    postData += "&_table_id=1";
    postData += "&_email_field=1.email";
    postData += "&_dedupe=1";
    postData += "&_static_update=1";
    postData += "&_rp=https://www.insidermedia.com/newsletter/subscription-successful";
    postData += "&_list_id=12";
    postData += "&_list_id=1";
    postData += "&_list_id=8";
    postData += "&_list_id=5";
    postData += "&_list_id=4";
    postData += "&_list_id=10";
    postData += "&_list_id=14";
    postData += "&_list_id=6";
    postData += "&_list_id=13";
    postData += "&_list_id=2035";
    postData += "&_list_id=7091";
    postData += "&_list_id=318";
    postData += "&_list_id=2";
    postData += "&_list_id=7294";
    postData += "&_list_id=317";
    postData += "&_list_id=8702";
    postData += "&_list_id=7298";
    postData += "&_list_id=7295";
    postData += "&_list_id=7297";
    postData += "&_list_id=10158";
    postData += "&_list_id=6419";
    postData += "&title=Mr";
    postData += "&first_name=fname_redacted";
    postData += "&surname=sname_redacted";
    postData += "&email=redactedg%40outlook.com";
    postData += "&company=cname_redacted";
    postData += "&position=Analyst";
    postData += "&add1=23 liverpool road";
    postData += "&add4=liverpool";
    postData += "&add5=bedfordshire";
    postData += "&postcode=l59uh";
    postData += "&telephone=1519838474";
    postData += "&sector=Accountants";
    postData += "&_employees=Less than 25";

    byte[] byteArray = Encoding.UTF8.GetBytes(postData);
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = byteArray.Length;
    Stream dataStream = request.GetRequestStream();
    dataStream.Write(byteArray, 0, byteArray.Length);
    dataStream.Close();
    WebResponse response = request.GetResponse(); // 403 forbidden

    Console.WriteLine(((HttpWebResponse)response).StatusDescription);
    dataStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(dataStream);
    string responseFromServer = reader.ReadToEnd();
    Console.WriteLine(responseFromServer);
    reader.Close();
    dataStream.Close();
    response.Close();
    Console.ReadLine();

WebResponse response = request.GetResponse(); // 403禁止

0 个答案:

没有答案