fix: post json with empty data

This commit is contained in:
debugtalk
2022-03-25 23:48:14 +08:00
parent 3d0c6a0d21
commit c99097113e
2 changed files with 135 additions and 5 deletions
+8 -5
View File
@@ -182,7 +182,6 @@ func (s *tStep) makeRequestMethod(entry *Entry) error {
}
func (s *tStep) makeRequestURL(entry *Entry) error {
u, err := url.Parse(entry.Request.URL)
if err != nil {
log.Error().Err(err).Msg("make request url failed")
@@ -230,10 +229,14 @@ func (s *tStep) makeRequestBody(entry *Entry) error {
if strings.HasPrefix(mimeType, "application/json") {
// post json
var body interface{}
err := json.Unmarshal([]byte(entry.Request.PostData.Text), &body)
if err != nil {
log.Error().Err(err).Msg("make request body failed")
return err
if entry.Request.PostData.Text == "" {
body = nil
} else {
err := json.Unmarshal([]byte(entry.Request.PostData.Text), &body)
if err != nil {
log.Error().Err(err).Msg("make request body failed")
return err
}
}
s.Request.Body = body
} else if strings.HasPrefix(mimeType, "application/x-www-form-urlencoded") {