Log on to cnblogs to publish an article

Source: Internet
Author: User

I used to perform a simulated logon search for a small system in CNET. However, my technology was not enough, and I died in the middle. However, there are still many gains in this process. This cnblogs article was published on that basis.

I will post the main code here for you to see:

This is the code section in the logon window:

View Code

1 string postData = string. format ("_ EVENTTARGET = & __ EVENTARGUMENT = & __ VIEWSTATE =/combine & __ EVENTVALIDATION =/wEWBQLWwpqPDQLyj/combine & tbUserName = {0} & tbPassword = {1} & btnLogin = login & txtReturnUrl = http://home.cnblogs.com /", txtName. text. trim (), txtPwd. text. trim ());
2 // This is some of the parameters when cnblogs is submitted
3 ASCIIEncoding encoding = new ASCIIEncoding ();
4 byte [] data = encoding. GetBytes (postData );
5 HttpWebRequest request = (HttpWebRequest) WebRequest. Create ("http://passport.cnblogs.com/login.aspx ");
6 request. Method = "Post ";
7 request. ContentType = "application/x-www-form-urlencoded ";
8 request. ContentLength = data. Length;
9 request. KeepAlive = true;
10 request. CookieContainer = container; // The returned cookie is appended to this container.
11 // send data
12
13 Stream newStream = request. GetRequestStream ();
14 newStream. Write (data, 0, data. Length );
15
16
17 HttpWebResponse response = (HttpWebResponse) request. GetResponse ();
18 newStream = response. GetResponseStream ();
19 StreamReader reader = new StreamReader (newStream, Encoding. UTF8 );
20 string text = reader. ReadToEnd ();
21 reader. Close ();
22 newStream. Close ();

Form effect:

  

This is the code section of the main form:

  

View Code

1 string postData = string. format ("_ EVENTTARGET = Editor $ Edit $ lkbPost & __ EVENTARGUMENT = & __ VIEWSTATE = & Editor $ Edit $ txbTitle = {0} & Editor $ Edit $ EditorBody = {1} & 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 = ", txtTitle. text, rtxtContent. text); // some parameters for data submission
2 string Url = @ "http://www.cnblogs.com/envenler/admin/EditPosts.aspx? Opt = 1 "; // URL to be submitted
3 ASCIIEncoding encoding = new ASCIIEncoding ();
4 byte [] byt = encoding. GetBytes (postData );
5 HttpWebRequest request = (HttpWebRequest) WebRequest. Create (Url );
6 request. Method = "Post ";
7 request. ContentType = "application/x-www-form-urlencoded ";
8 request. ContentLength = byt. Length;
9 request. KeepAlive = true;
10 request. CookieContainer = Ccontainter; // The returned cookie is appended to this container.
11 // send data
12
13 Stream newStream = request. GetRequestStream ();
14 newStream. Write (byt, 0, byt. Length );
15 HttpWebResponse response = (HttpWebResponse) request. GetResponse ();
16 newStream = response. GetResponseStream ();
17 StreamReader reader = new StreamReader (newStream, Encoding. UTF8 );
18 string text = reader. ReadToEnd ();
19 reader. Close ();
20 newStream. Close ();

 

Form effect:

  

Final attach this all source code: http://files.cnblogs.com/envenler/cnblogsLogin.rar (this seems a bit problematic, if you need to download please copy the link to the browser to open .)

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.