feat: post form data

This commit is contained in:
debugtalk
2021-10-15 21:25:20 +08:00
parent 65712f626a
commit d5cbd1820e
2 changed files with 12 additions and 1 deletions

View File

@@ -197,7 +197,12 @@ func (s *TStep) makeRequestBody(entry *Entry) error {
}
s.Request.Body = body
} else if strings.HasPrefix(mimeType, "application/x-www-form-urlencoded") {
// TODO: post form data
// post form
var paramsList []string
for _, param := range entry.Request.PostData.Params {
paramsList = append(paramsList, fmt.Sprintf("%s=%s", param.Name, param.Value))
}
s.Request.Body = strings.Join(paramsList, "&")
}
return nil
}

View File

@@ -87,7 +87,13 @@ func TestMakeTestCase(t *testing.T) {
}
// make request data
if !assert.Equal(t, nil, tCase.TestSteps[0].Request.Body) {
t.Fail()
}
if !assert.Equal(t, map[string]interface{}{"foo1": "HDnY8", "foo2": 12.3}, tCase.TestSteps[1].Request.Body) {
t.Fail()
}
if !assert.Equal(t, "foo1=HDnY8&foo2=12.3", tCase.TestSteps[2].Request.Body) {
t.Fail()
}
}