Objective: To use. netCodeLog on to. NET and submitArticleArticle 1
Note: For post requests on the Asp.net page, the server will verify the submitted _ viewstate and _ eventvalidation. Therefore, the two fields must be submitted during the request.
Obtain the content of the _ viewstate and _ eventvalidation fields, and submit the data to log on to the garden.
// Obtain the HTML content of the URL page var loginpagehtml = requesthelper. getresponsecontent (URL); // get _ viewstate, _ eventvalidation _ viewstate = RegEx. match (loginpagehtml, reg1 ). groups [1]. value; _ eventvalidation = RegEx. match (loginpagehtml, reg2 ). groups [1]. value; // the submitted data dictionary <string, string> dicdata = new dictionary <string, string> () {"_ viewstate" ,__ viewstate }, {"_ eventvalidation", _ eventvalidation}, {"tbusername", "username" },{ "tbpassword", "password" },{ "_ eventtarget ", "" },{ "_ eventargument", "" },{ "btnlogin", "login "}}; // The data dictionary submitted by splicing is a = 1 & B = 2 var postdata = dicdata. select (DIC => string. format ("{0} = {1}", DIC. key, DIC. value )). aggregate (a, B) => A + "&" + B); // submit the logon page request and obtain the response object var response = requesthelper. getresponse (URL, postdata, (head) => {head. method = "Post"; head. useragent = "Mozilla/5.0"; head. cookiecontainer = cc ;});
Log on to the post page and submit an article. The Code is as follows:
// Submit an article var editpostpagehtml = requesthelper. getresponsecontent ("http://www.cnblogs.com/lyroge/admin/EditPosts.aspx? Opt = 1 ", null, (head) => {head. cookiecontainer = cc; head. allowautoredirect = true;}); _ viewstate = RegEx. match (editpostpagehtml, reg1 ). groups [1]. value; var dicdata = new dictionary <string, string> () {"_ viewstate" ,__ viewstate },{ "_ eventtarget ",""}, {"_ eventargument", "" },{ "editor $ edit $ lkbpost", "publish" },{ "editor $ edit $ txbtitle ",".. Net log on to the blog Park and post an article "},{" editor $ edit $ editorbody "," <p> content I enter by myself </P> "},{" Editor $ edit $ apoptions $ apsitehome $ chkdisplayhomepage "," on "},{" editor $ edit $ advanced $ ckbpublished "," on "}, {"editor $ edit $ advanced $ chkcomments", "on" },{ "editor $ edit $ advanced $ chkmainsyndication", "on "}, {"editor $ edit $ advanced $ txbentryname", "" },{ "editor $ edit $ advanced $ txbexcerpt ",""}, {"editor $ edit $ advanced $ txbtag", "" },{ "editor $ edit $ advanced $ tbenrypassword ",""}}; // note that the submitted data must be urlencode-encoded va R postdata = dicdata. select (DIC => string. format ("{0} = {1}", system. web. httputility. urlencode (DIC. key), system. web. httputility. urlencode (DIC. value ))). aggregate (a, B) => A + "&" + B); var response = requesthelper. getresponse ("http://www.cnblogs.com/lyroge/admin/EditPosts.aspx? Opt = 1 ", postdata, (head) => {head. method = "Post"; head. useragent = "Mozilla/5.0"; head. cookiecontainer = cc; head. referer = "http://www.cnblogs.com ";});