zoukankan      html  css  js  c++  java
  • C#模拟POST登录cnblogs并发布文章

    用到的工具FireFox的Firebugs插件 打开网络功能进行抓包 数据如下

    可以得知POST的数据为:

    __EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=%2FwEPDwULLTE1MzYzODg2NzZkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBQtjaGtSZW1lbWJlcm1QYDyKKI9af4b67Mzq2xFaL9Bt&__EVENTVALIDATION=%2FwEWBQLWwpqPDQLyj%2FOQAgK3jsrkBALR55GJDgKC3IeGDE1m7t2mGlasoP1Hd9hLaFoI2G05&tbUserName=账户&tbPassword=密码&btnLogin=%E7%99%BB++%E5%BD%95&txtReturnUrl=http%3A%2F%2Fhome.cnblogs.com%2F

    在VS里画登陆图

     

     查看别人的代码  登录代码:

    string postData =string.Format( "__EVENTTARGET=&__EVENTARGUMENT=&__VIEWSTATE=/wEPDwULLTE1MzYzODg2NzZkGAEFHl9fQ29udHJvbHNSZXF1aXJlUG9zdEJhY2tLZXlfXxYBBQtjaGtSZW1lbWJlcm1QYDyKKI9af4b67Mzq2xFaL9Bt&__EVENTVALIDATION=/wEWBQLWwpqPDQLyj/OQAgK3jsrkBALR55GJDgKC3IeGDE1m7t2mGlasoP1Hd9hLaFoI2G05&tbUserName={0}&tbPassword={1}&btnLogin=登 录&txtReturnUrl=http://home.cnblogs.com/",txtName.Text.Trim(),txtPwd.Text.Trim());
    //这是cnblogs提交时的一些参数
    ASCIIEncoding encoding = new ASCIIEncoding();
    byte[] data = encoding.GetBytes(postData);
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://passport.cnblogs.com/login.aspx");
    request.Method = "Post";
    request.ContentType = "application/x-www-form-urlencoded";
    request.ContentLength = data.Length;
    request.KeepAlive = true;
    request.CookieContainer = container; //返回的cookie会附加在这个容器里面
    //发送数据

    Stream newStream = request.GetRequestStream();
    newStream.Write(data, 0, data.Length);


    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    newStream = response.GetResponseStream();
    StreamReader reader = new StreamReader(newStream, Encoding.UTF8);
    string text = reader.ReadToEnd();
    reader.Close();
    newStream.Close();

  • 相关阅读:
    R语言实战实现基于用户的简单的推荐系统(数量较少)
    MapReduce计数器
    MapReduce的Shuffle过程介绍
    R语言两种方式求指定日期所在月的天数
    ggplot2作图详解:入门函数qplot
    R语言中的数据处理包dplyr、tidyr笔记
    Metronic_下拉列表Select2插件的使用
    Linux_使用Linux之安装jdk 7
    HttpClient_HttpClient 4.3.6 HTTP状态管理
    HttpClient_HttpClient 对 cookie的处理
  • 原文地址:https://www.cnblogs.com/wangluochong/p/4577175.html
Copyright © 2011-2022 走看看