Compare commits
2 Commits
d437bfae2b
...
c0397c568e
Author | SHA1 | Date |
---|---|---|
|
c0397c568e | |
|
8fe8d3f716 |
19
request.go
19
request.go
|
@ -22,6 +22,7 @@ type Request struct {
|
|||
Files map[string]string `json:"files"` // todo 处理 Files
|
||||
Raw string `json:"raw"` // 原始请求数据
|
||||
JsonByte []byte `json:"json_raw"` // JSON格式请求数据 todo 多层 嵌套
|
||||
Xml []byte `json:"xml"` // xml
|
||||
}
|
||||
|
||||
// 响应结构体
|
||||
|
@ -69,14 +70,26 @@ func (r *Request) getData() io.Reader {
|
|||
urlValues.Add(key, value)
|
||||
}
|
||||
reqBody = urlValues.Encode()
|
||||
r.Headers["Content-Type"] = "application/x-www-form-urlencoded"
|
||||
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)
|
||||
r.Headers["Content-Type"] = "application/json"
|
||||
if _, ex := r.Headers["Content-Type"]; !ex {
|
||||
r.Headers["Content-Type"] = "application/json"
|
||||
}
|
||||
} else if r.JsonByte != nil {
|
||||
reqBody = string(r.JsonByte)
|
||||
r.Headers["Content-Type"] = "application/json"
|
||||
if _, ex := r.Headers["Content-Type"]; !ex {
|
||||
r.Headers["Content-Type"] = "application/json"
|
||||
}
|
||||
} else if r.Xml != nil {
|
||||
reqBody = string(r.Xml)
|
||||
if _, ex := r.Headers["Content-Type"]; !ex {
|
||||
r.Headers["Content-Type"] = "application/xml"
|
||||
}
|
||||
}
|
||||
return strings.NewReader(reqBody)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue