mirror of
https://github.com/httprunner/httprunner.git
synced 2026-05-13 08:59:44 +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}
|
||||
|
||||
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{
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user