mirror of
https://github.com/httprunner/httprunner.git
synced 2026-09-05 07:26:55 +08:00
fix: add slice type of request body data
This commit is contained in:
@@ -282,14 +282,22 @@ func (s *tStep) makeValidate(entry *Entry) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
if strings.HasPrefix(respBody.MimeType, "application/json") {
|
if strings.HasPrefix(respBody.MimeType, "application/json") {
|
||||||
|
var data []byte
|
||||||
|
var err error
|
||||||
// response body is json
|
// response body is json
|
||||||
if respBody.Encoding == "base64" {
|
if respBody.Encoding == "base64" {
|
||||||
// decode base64 text
|
// decode base64 text
|
||||||
data, err := base64.StdEncoding.DecodeString(respBody.Text)
|
data, err = base64.StdEncoding.DecodeString(respBody.Text)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.Wrap(err, "decode base64 error")
|
return errors.Wrap(err, "decode base64 error")
|
||||||
}
|
}
|
||||||
|
} else if respBody.Encoding == "" {
|
||||||
|
// no encoding
|
||||||
|
data = []byte(respBody.Text)
|
||||||
|
} else {
|
||||||
|
// other encoding type
|
||||||
|
return nil
|
||||||
|
}
|
||||||
// convert to json
|
// convert to json
|
||||||
var body interface{}
|
var body interface{}
|
||||||
if err = json.Unmarshal(data, &body); err != nil {
|
if err = json.Unmarshal(data, &body); err != nil {
|
||||||
@@ -324,7 +332,6 @@ func (s *tStep) makeValidate(entry *Entry) error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -716,6 +716,16 @@ func (r *caseRunner) runStepRequest(step *TStep) (stepResult *stepData, err erro
|
|||||||
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
case []interface{}:
|
||||||
|
contentType := req.Header.Get("Content-Type")
|
||||||
|
// post json
|
||||||
|
dataBytes, err = json.Marshal(vv)
|
||||||
|
if err != nil {
|
||||||
|
return stepResult, err
|
||||||
|
}
|
||||||
|
if contentType == "" {
|
||||||
|
req.Header.Set("Content-Type", "application/json; charset=utf-8")
|
||||||
|
}
|
||||||
case string:
|
case string:
|
||||||
dataBytes = []byte(vv)
|
dataBytes = []byte(vv)
|
||||||
case []byte:
|
case []byte:
|
||||||
|
|||||||
Reference in New Issue
Block a user