示例#1
0
文件: login.go 项目: disunbow/request
func home(req *request.Request) (statusCode int) {
	resp, err := req.Get(loginRequiredPageURL)
	if err != nil {
		return 500
	}
	return resp.StatusCode
}
示例#2
0
func diff(req *request.Request) {
	url := "http://example.com:12345"
	start := time.Now()

	req.Get(url)

	diff := time.Now().Sub(start)
	fmt.Println(diff.Seconds())
}
示例#3
0
文件: login.go 项目: disunbow/request
func getCSRFToken(req *request.Request) (string, error) {
	resp, err := req.Get(loginPageURL)
	if err != nil {
		return "", err
	}
	s, err := resp.Text()
	if err != nil {
		return "", err
	}

	reInput := regexp.MustCompile(
		`<input\s+[^>]*?name=['"]csrfmiddlewaretoken['"'][^>]*>`,
	)
	input := reInput.FindString(s)
	reValue := regexp.MustCompile(`value=['"]([^'"]+)['"]`)
	csrfToken := reValue.FindStringSubmatch(input)
	if len(csrfToken) < 2 {
		return "", err
	}
	return csrfToken[1], err
}