. Net log on to the blog and post an article

Source: Internet
Author: User

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 ";});

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.