自动更新
This commit is contained in:
parent
18e189844f
commit
9ea74e0a8a
@ -14,6 +14,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"mime/multipart"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
@ -224,6 +225,33 @@ func (s *SimpleRequest) initBody() {
|
||||
} else {
|
||||
s.body = bytes.NewReader([]byte("{}"))
|
||||
}
|
||||
case contentTypeData == formDataType:
|
||||
body := &bytes.Buffer{}
|
||||
writer := multipart.NewWriter(body)
|
||||
//data := url.Values{}
|
||||
for k, sv := range s.tempBody {
|
||||
switch sv.(type) {
|
||||
case string:
|
||||
strSv, _ := sv.(string)
|
||||
_ = writer.WriteField(k, strSv)
|
||||
//data.Set(k, strSv)
|
||||
case []string:
|
||||
sss, _ := sv.([]string)
|
||||
for _, v := range sss {
|
||||
_ = writer.WriteField(k, v)
|
||||
//data.Add(k, v)
|
||||
}
|
||||
}
|
||||
}
|
||||
err := writer.Close()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
s.headers.Set("Content-Type", writer.FormDataContentType())
|
||||
//strD := data.Encode()
|
||||
//bodyText := strings.NewReader(strD)
|
||||
s.body = body
|
||||
|
||||
case contentTypeData == xmlDataType || contentTypeData == textPlainType || contentTypeData == javaScriptType:
|
||||
data, _ := s.tempBody[stringBodyType].(string)
|
||||
s.body = strings.NewReader(data)
|
||||
|
23
test/data_test.go
Normal file
23
test/data_test.go
Normal file
@ -0,0 +1,23 @@
|
||||
/*
|
||||
* @FileName: dataTest.go
|
||||
* @Author: JuneXu
|
||||
* @CreateTime: 2022/3/24 下午9:18
|
||||
* @Description:
|
||||
*/
|
||||
|
||||
package test
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestData(t *testing.T) {
|
||||
type dt map[string][]string
|
||||
var newData = dt{
|
||||
"aa": []string{"aa", "cc"},
|
||||
}
|
||||
res, err := json.Marshal(&newData)
|
||||
t.Log(err)
|
||||
t.Log(res)
|
||||
}
|
@ -48,3 +48,20 @@ func TestRequest(t *testing.T) {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func TestAuth(t *testing.T) {
|
||||
req := simpleRequest.NewRequest()
|
||||
req.Headers().ConentType_formData()
|
||||
req.Headers().SetRandomUerAgent()
|
||||
req.Body().Set("grant_type", "password")
|
||||
req.Body().Set("client_id", "smz")
|
||||
req.Body().Set("client_secret", "smz")
|
||||
req.Body().Set("scope", "getdata")
|
||||
req.Body().Set("username", "shiming_zyf")
|
||||
req.Body().Set("password", "zyf499bbcb9")
|
||||
|
||||
var URL = "https://shiming.cn-jzs.com/oauth/token"
|
||||
|
||||
data, _ := req.Post(URL)
|
||||
t.Log(string(data))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user