golang模拟登录本校

登录网站的表单页面网址为:http://jwxt.wit.edu.cn/jsxsd/

通过golang提供的http请求包发送请求初次获取cookie

    clientLogin1 := &http.Client{}
	reqLogin1, err := http.NewRequest(method, urlLogin1, nil)
	if err != nil {
		fmt.Println(err)
		return ""
	}
	resLogin1, err := clientLogin1.Do(reqLogin1)
	if err != nil {
		fmt.Println(err)
		return ""
	}
	defer resLogin1.Body.Close()
	cookie := resLogin1.Cookies()

通过fidder抓包得知,表单提交数据的网址为:http://jwxt.wit.edu.cn/jsxsd/xk/LoginToXk

并对提交的数据进行了加密,通过查看页面源代码得知加密方式为base64加密

使用golang提供base64加密包对数据进行加密

    encodeduser := base64.StdEncoding.EncodeToString([]byte(username))
	encodedpass := base64.StdEncoding.EncodeToString([]byte(password))
	encoded := encodeduser + "%%%" + encodedpass

再次发送请求并携带数据,使初次获取的cookie生效

    reqLogin2, err := http.NewRequest("POST", urlLogin2, payload)
	if err != nil {
		fmt.Println(err)
		return ""
	}
	reqLogin2.Header.Add("Content-Type", "application/x-www-form-urlencoded")
	reqLogin2.Header.Add("Cookie", cookies)
	resLogin2, err := clientLogin2.Do(reqLogin2)

完成模拟登录

上一篇:点分治


下一篇:word文档的图片怎么保存到TinyMCE上