Skip to content

jetamie/request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Golang封装请求(带cookie)

安装方法

go get github.com/jetamie/request

使用方法

package main

import (
	"github.com/jetamie/request"
)

func main() {
	r := request.NewRequest()
	body := r.SetLog(false).Request("http://www.10jqka.com.cn")
	println(body)
}

模块测试用例

package request

import (
	"testing"
)

func TestRequest_SetHost(t *testing.T) {
	r := NewRequest()
	//配置域名host访问
	r.SetHost("www.baidu.com").Request("http://112.80.248.75:80")

}

func TestRequest_SetLog(t *testing.T) {
	r := NewRequest()
	//打印相关请求信息,默认false
	r.SetLog(true).Request("https://www.baidu.com")
}

func TestRequest_SetPostData(t *testing.T) {
	r := NewRequest()
	//发送post数据
	post := map[string]string{}
	post["username"] = "xxx"
	post["password"] = "xxx"
	r.SetPostData(post).Request("https://passport.baidu.com/v2/api/?login")
}

func TestRequest_Request(t *testing.T) {
	//普通GET请求
	r := NewRequest()
	r.Request("https://www.baidu.com")
	//t.Logf("body:%s\r\n", body)
}

func TestRequest_PrintCookie(t *testing.T) {
	//打印cookies信息
	r := NewRequest()
	r.Request("https://www.baidu.com")
	r.PrintCookie()
}

版本功能介绍

v0.1

  • get/post请求(带cookie)
  • 请求https时跳过ssl证书验证
  • 允许动态设置Host访问
  • 允许获取当前用户请求的cookie

交流:[email protected]

About

Golang封装请求(带cookie)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages