PostForm 与 其他形式的分辨 bug

This commit is contained in:
huangsimin 2018-10-25 18:45:46 +08:00
parent 025f911c0e
commit 8a0a21fc5e
3 changed files with 12 additions and 4 deletions

12
base.go
View File

@ -10,10 +10,12 @@ import (
func buildBodyRequest(ver, rawurl string, body *Body) *http.Request {
var req *http.Request
var err error
contentType := ""
if body.IOBody == nil {
req, err = http.NewRequest(ver, rawurl, nil)
} else {
contentType = TypeURLENCODED
var bodybuf *bytes.Buffer
switch body.IOBody.(type) {
case []byte:
@ -30,10 +32,12 @@ func buildBodyRequest(ver, rawurl string, body *Body) *http.Request {
panic(err)
}
if body.ContentType == "" {
req.Header.Set(HeaderKeyContentType, TypeURLENCODED)
} else {
req.Header.Set(HeaderKeyContentType, body.ContentType)
if body.ContentType != "" {
contentType = body.ContentType
}
if contentType != "" {
req.Header.Set(HeaderKeyContentType, contentType)
}
return req

View File

@ -48,6 +48,8 @@ const (
TypeXML = "text/xml"
// TypeURLENCODED 类型
TypeURLENCODED = "application/x-www-form-urlencoded"
// TypeForm PostForm类型
TypeForm = TypeURLENCODED
// TypeFormData 类型
TypeFormData = "multipart/form-data"
// HeaderKeyHost Host

View File

@ -1,6 +1,7 @@
package requests
import (
"log"
"net/http"
"net/url"
"regexp"
@ -231,6 +232,7 @@ func mergeMapList(headers ...map[string][]string) map[string][]string {
// setHeaderRequest 设置request的头
func setHeaderRequest(req *http.Request, wf *Workflow) {
req.Header = mergeMapList(req.Header, wf.session.Header, wf.Header)
log.Println(wf.Header, wf.session.Header)
}
// setHeaderRequest 设置request的临时Cookie, 永久需要在session上设置cookie