Compare commits
No commits in common. "v1.0.6" and "v1" have entirely different histories.
2
go.mod
2
go.mod
|
@ -1,3 +1,3 @@
|
|||
module gitea.cdlsxd.cn/self-tools/l_request
|
||||
module gitea.cdlsxd.cn/self-tools/l-request
|
||||
|
||||
go 1.21
|
||||
|
|
25
request.go
25
request.go
|
@ -1,7 +1,6 @@
|
|||
package l_request
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"encoding/json"
|
||||
"io"
|
||||
"net/http"
|
||||
|
@ -69,22 +68,15 @@ func (r *Request) getData() io.Reader {
|
|||
urlValues.Add(key, value)
|
||||
}
|
||||
reqBody = urlValues.Encode()
|
||||
if _, ex := r.Headers["Content-Type"]; !ex {
|
||||
r.Headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||
}
|
||||
|
||||
} else if r.Json != nil {
|
||||
bytesData, _ := json.Marshal(r.Json)
|
||||
reqBody = string(bytesData)
|
||||
if _, ex := r.Headers["Content-Type"]; !ex {
|
||||
r.Headers["Content-Type"] = "application/json"
|
||||
}
|
||||
} else if r.JsonByte != nil {
|
||||
reqBody = string(r.JsonByte)
|
||||
if _, ex := r.Headers["Content-Type"]; !ex {
|
||||
r.Headers["Content-Type"] = "application/json"
|
||||
}
|
||||
}
|
||||
return strings.NewReader(reqBody)
|
||||
}
|
||||
|
||||
|
@ -136,20 +128,3 @@ func (r *Request) Send() (Response, error) {
|
|||
elapsed := time.Since(start).Seconds()
|
||||
return r.packResponse(res, elapsed), nil
|
||||
}
|
||||
|
||||
// 跳过证书发送请求
|
||||
func (r *Request) SendWithoutSsl() (Response, error) {
|
||||
tr := &http.Transport{
|
||||
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
|
||||
}
|
||||
req := r.prepare()
|
||||
client := &http.Client{Transport: tr}
|
||||
start := time.Now()
|
||||
res, err := client.Do(req)
|
||||
if err != nil {
|
||||
return Response{}, err
|
||||
}
|
||||
defer res.Body.Close()
|
||||
elapsed := time.Since(start).Seconds()
|
||||
return r.packResponse(res, elapsed), nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue