Test Overview
This test sends a POST request with an x-www-form-urlencoded body to an API endpoint and verifies the response status and body content.
This test sends a POST request with an x-www-form-urlencoded body to an API endpoint and verifies the response status and body content.
pm.test("POST request with x-www-form-urlencoded body", function () { pm.sendRequest({ url: 'https://postman-echo.com/post', method: 'POST', header: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: { mode: 'urlencoded', urlencoded: [ { key: 'username', value: 'testuser' }, { key: 'password', value: 'testpass' } ] } }, function (err, res) { pm.expect(err).to.be.null; pm.expect(res).to.have.property('code', 200); const jsonData = res.json(); pm.expect(jsonData.form).to.have.property('username', 'testuser'); pm.expect(jsonData.form).to.have.property('password', 'testpass'); }); });
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test starts: Prepare POST request with x-www-form-urlencoded body containing username and password | Postman environment ready to send request | — | PASS |
| 2 | Send POST request to https://postman-echo.com/post with Content-Type header set to application/x-www-form-urlencoded | Request sent, waiting for response | — | PASS |
| 3 | Receive response from server | Response received with status code 200 and JSON body | Check response status code is 200 | PASS |
| 4 | Parse JSON response body and verify form data contains username and password with correct values | Response JSON parsed: form data includes username='testuser' and password='testpass' | Assert form.username == 'testuser' and form.password == 'testpass' | PASS |
| 5 | Test completes successfully | All assertions passed, test finished | — | PASS |
x-www-form-urlencoded body type do in Postman?x-www-form-urlencoded sends form data as key-value pairs joined by '&' in the request body, similar to how HTML forms send data.x-www-form-urlencoded uses key-value pairs joined by '&'.x-www-form-urlencoded body tab?x-www-form-urlencoded body tab shows two columns: one for keys and one for values.x-www-form-urlencoded body:username: user1password: pass@123x-www-form-urlencoded body in Postman with keys and values, but the server responds with a 400 Bad Request error. What is the most likely cause?x-www-form-urlencoded data, the Content-Type header must be set to application/x-www-form-urlencoded so the server knows how to parse the body.x-www-form-urlencoded body in Postman with keys username and password. The password contains spaces and special characters like pass word@123!. How should you prepare the body to ensure the server receives it correctly?x-www-form-urlencoded body type.Pass the test and this pattern moves unknown