mirror of
https://github.com/httprunner/httprunner.git
synced 2026-06-09 17:59:36 +08:00
fix: convert postman body in json
This commit is contained in:
@@ -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