mirror of
https://github.com/httprunner/httprunner.git
synced 2026-07-10 23:12:41 +08:00
fix: convert postman body in json
This commit is contained in:
@@ -81,7 +81,7 @@ func TestConsoleOutput(t *testing.T) {
|
|||||||
data["stats"] = []interface{}{stat}
|
data["stats"] = []interface{}{stat}
|
||||||
|
|
||||||
stat["name"] = "http"
|
stat["name"] = "http"
|
||||||
stat["method"] = "post"
|
stat["method"] = "POST"
|
||||||
stat["num_requests"] = int64(100)
|
stat["num_requests"] = int64(100)
|
||||||
stat["num_failures"] = int64(10)
|
stat["num_failures"] = int64(10)
|
||||||
stat["response_times"] = map[int64]int64{
|
stat["response_times"] = map[int64]int64{
|
||||||
|
|||||||
@@ -330,29 +330,17 @@ func (s *stepFromPostman) makeRequestBodyRaw(item *TItem) (err error) {
|
|||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
// extract language type, default languageType: text
|
s.Request.Body = item.Request.Body.Raw
|
||||||
languageType := "text"
|
contentType := s.Request.Headers["Content-Type"]
|
||||||
iOptions := item.Request.Body.Options
|
if strings.Contains(contentType, "application/json") {
|
||||||
if iOptions != nil {
|
|
||||||
iLanguage := iOptions.(map[string]interface{})["raw"]
|
|
||||||
if iLanguage != nil {
|
|
||||||
languageType = iLanguage.(map[string]interface{})["language"].(string)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// make request body and indicate Content-Type
|
|
||||||
rawBody := item.Request.Body.Raw
|
|
||||||
if languageType == "json" {
|
|
||||||
var iBody interface{}
|
var iBody interface{}
|
||||||
err = json.Unmarshal([]byte(rawBody), &iBody)
|
err = json.Unmarshal([]byte(item.Request.Body.Raw), &iBody)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
log.Warn().Err(err).Msg("33333")
|
||||||
return errors.Wrap(err, "make request body (raw -> json) failed")
|
return errors.Wrap(err, "make request body (raw -> json) failed")
|
||||||
}
|
}
|
||||||
s.Request.Body = iBody
|
s.Request.Body = iBody
|
||||||
} else {
|
|
||||||
s.Request.Body = rawBody
|
|
||||||
}
|
}
|
||||||
s.Request.Headers["Content-Type"] = contentTypeMap[languageType]
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user