Maitiro Ekutumira Fomu Dhata Ne REST-yakavimbiswa Post Chikumbiro

Maitiro ekutumira POST chikumbiro uine REST-yakavimbiswa. HTML Mafomu anoshandisa POST chikumbiro kuendesa fomu data uye mune ino dzidziso, isu tinoshandisa REST-yakasimbiswa kuendesa fomu.

POST chikumbiro chine zvinhu zvina:

URL : Iyi ndiyo nzvimbo yesosi yatinotumira dhata kwariri, i.e. www.example.com/login

Chiito : kana tichiendesa data, isu tinoshandisa iyo POST chikumbiro.

VAKURU : aya ndiwo ekukumbira misoro, senge Gamuchira kana Zvemukati-Type.

MUVIRI : body Ine iyo data iyo yatinotumira sekukumbira kwepositi. Semuenzaniso, kana uchiendesa fomu, fomu re data rinotumirwa mumuviri wechikumbiro.

REST-yakasimbiswa POST chikumbiro

Iyo yekuenzanisira kodhi pazasi inoratidza maitiro ekuendesa fomu fomu sePOST chikumbiro uine REST-yakasimbiswa, mhando 3.2.0 .


io.rest-assured
rest-assured
3.2.0
test
import io.restassured.RestAssured; import io.restassured.http.ContentType; import org.junit.Test; import static io.restassured.RestAssured.given; public class restAssuredPostRequest {
@Test
public void submitForm() {
RestAssured.baseURI = 'https://www.example.com';
given().urlEncodingEnabled(true)

.param('username', 'user@site.com')

.param('password', 'Pas54321')

.header('Accept', ContentType.JSON.getAcceptHeader())

.post('/login')

.then().statusCode(200);
} }

Inoenderana:

REST-yakasimbiswa POST JSON Payload

Kunze kwekutumira Fomu dhata, unogona zvakare kushandisa REST-yakavimbiswa POST chikumbiro kutumira JSON kubhadhara kune chimwe chigadzirwa. Heino muenzaniso:

import io.restassured.http.ContentType; import io.restassured.response.Response; import static io.restassured.RestAssured.given; public class PostJsonPayload {
private static String payload = '{ ' +
' 'description': 'Some Description', ' +
' 'id': 'Some id', ' +
' 'name': 'Some name' ' +
'}';

public static Response postJsonPayload() {
return

given()

.contentType(ContentType.JSON)

.body(payload)

.post('/some/resource')

.then()

.statusCode(200)

.extract()

.response();
} }