fix: convert postman body in json

This commit is contained in:
debugtalk
2022-12-23 14:03:53 +08:00
parent e3596a6051
commit eeae8b2961
2 changed files with 6 additions and 18 deletions

View File

@@ -81,7 +81,7 @@ func TestConsoleOutput(t *testing.T) {
data["stats"] = []interface{}{stat}
stat["name"] = "http"
stat["method"] = "post"
stat["method"] = "POST"
stat["num_requests"] = int64(100)
stat["num_failures"] = int64(10)
stat["response_times"] = map[int64]int64{

View File

@@ -330,29 +330,17 @@ func (s *stepFromPostman) makeRequestBodyRaw(item *TItem) (err error) {
}
}()
// extract language type, default languageType: text
languageType := "text"
iOptions := item.Request.Body.Options
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" {
s.Request.Body = item.Request.Body.Raw
contentType := s.Request.Headers["Content-Type"]
if strings.Contains(contentType, "application/json") {
var iBody interface{}
err = json.Unmarshal([]byte(rawBody), &iBody)
err = json.Unmarshal([]byte(item.Request.Body.Raw), &iBody)
if err != nil {
log.Warn().Err(err).Msg("33333")
return errors.Wrap(err, "make request body (raw -> json) failed")
}
s.Request.Body = iBody
} else {
s.Request.Body = rawBody
}
s.Request.Headers["Content-Type"] = contentTypeMap[languageType]
return
}