github.com/jtzjtz/kit@v1.0.2/http/http_request_test.go (about)

     1  package http
     2  
     3  import (
     4  	"github.com/gin-gonic/gin"
     5  	"net/http"
     6  	"strconv"
     7  	"testing"
     8  	"time"
     9  )
    10  
    11  func TestPostJson(t *testing.T) {
    12  	ctx := new(gin.Context)
    13  	ctx.Request = new(http.Request)
    14  	ctx.Request.Header = http.Header{}
    15  	traceid := strconv.Itoa(int(time.Now().UnixNano()))
    16  	ctx.Request.Header.Set(TRACEID, traceid)
    17  	data := make(map[string]interface{})
    18  	data["productSn"] = "SN163029560033161249194"
    19  	extparams := new(ExtParams)
    20  	extparams.Headers = map[string]string{}
    21  	extparams.Headers["Authorization"] = "Bearer dd3pjjsjss"
    22  	resbody, httpstatus, er := PostJson("https://api.ttjianbao.com/api/mall/product/getProductDetail", data, extparams, ctx)
    23  	if er != nil || httpstatus != 200 || len(resbody) == 0 {
    24  		t.Error(er)
    25  	}
    26  	println(traceid)
    27  	println(resbody)
    28  }