Golang, Python log in to open source China, and publish a blog.

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

GO, Python can not be done in more than 10 minutes, easy language, may be a few minutes to finish, domestic easy language feel fast ah.

Type loginsave struct {Returnck []*http. Cookie}type Oschina Interface {login (user string, pass string) string save (title string, content String) String}func Main () {User: = "xxxxxx@qq.com"//Account Pass: = "xxxxxxxxxx"//password user = strings. Replace (User, "@", "%40", 1) pass = (Shacryto (pass)) Lo: = Loginsave{[]*http. cookie{}} lo.login (user, pass) lo.save ("Testall", "Look at Me")}func Shacryto (src String) string {h: = SHA1. New () H.write ([]byte (SRC)) return hex. Encodetostring (H.sum (nil))}func (lo *loginsave) login (user, pass String) string {client: = &http. client{} req, err: = http. Newrequest ("POST", "Https://www.oschina.net/action/user/hash_login", strings.   Newreader ("email=" +user+ "&pwd=" +pass+ "&verifycode=&save_login=1")) if err! = Nil {//Handle error} Req. Header.set ("Content-type", "application/x-www-form-urlencoded") resp, err: = client. Do (req) defer resp. Body.close () body, err: = Ioutil. ReadAll (resp. Body) If err! = Nil{//Handle error} Lo.returnck = resp. Cookies () fmt. Println (String (body)) fmt. Println ("==================") return "1"}func (sa *loginsave) Save (title string, content String) string {client: = &A Mp;http. client{} fmt. Println (Sa.returnck) req, err: = http. Newrequest ("POST", "Https://my.oschina.net/action/blog/save", strings. Newreader ("draft=590308&user_code=xowizssfmaowkbf0oldqjnujch2vdgufhcgc55py&id=&catalog=286094& Title= "+title+" &content_type=4&tags=&classification=428640&type=1&origin_url=&privacy= 1&deny_comment=1&as_top=0&isrecommend=on&abstracts=&content=%3cp%3e "+content+"%3C%2Fp%3E%0 a&temp=1490495330601 ")) if err! = Nil {//Handle error} FMT. Println (Sa.returnck) req. Header.set ("Content-type", "application/x-www-form-urlencoded") for _, I: = Range Sa.returnck {req. Addcookie (i)} resp, err: = client. Do (req) defer resp. Body.close () body, err: = Ioutil. ReadAll (resp. BodyIf err! = Nil {//Handle error} FMT. Println (resp. Cookies ()) fmt. Println (String) return "1"}

Python's words, did not write, because I do this post program to vomit, estimated to do hundreds of.

Related Article

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.