import static com.jayway.restassured.RestAssured.given;
import com.jayway.restassured.builder.RequestSpecBuilder;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.specification.RequestSpecification;
public class PUTAPI {
public void addNewObject() throws Throwable {
//Creating api body
String xmlBody ="<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
+"<PlanRunRequest>"
+"<PlannedRunName>LIMS_Plan_Run_001</PlannedRunName>"
+"<Assay></Assay>"
+"<ReportingTemplate>LIMS_Report1</ReportingTemplate>"
+"<TubeLabel>tube2343</TubeLabel>"
+"<TemplateKitBarcode>91A18930101212-1234567171603172100001301</TemplateKitBarcode>"
+"<PlanRunNotes>This is my 1st Plan</PlanRunNotes>"
+"<LibraryPrepIDs>"
+"<LibraryPrepID specimenID=\"\">1004</LibraryPrepID>"
+"</LibraryPrepIDs>"
+"</PlanRunRequest>";
System.out.println(xmlBody);
//Specifying request body details
RequestSpecBuilder builder = new RequestSpecBuilder().setContentType("application/xml");
RequestSpecification requestSpec = builder.build();
requestSpec.baseUri("http://10.88.195.88").basePath("/ir/lims/create-library-batch").contentType("application/xml");
//Making post request with authentication
Response response =given().body(xmlBody).header("username","Auto1Admin").header("password", "ion123").spec(requestSpec).when().put();
System.out.println("ir"+response.body().asString());
System.out.println(response.getStatusCode() );
}
public static void main (String [] args) throws Throwable {
PUTAPI service = new PUTAPI();
service.addNewObject();
}
}
已验证&#39; String xmlBody&#39;即带XML-validator的XML请求体,未发现错误。通过邮递员提交此查询,验证请求URI,正文和标题。它显示了我成功的响应代码200 k,但是当我运行上面的脚本有正确的URI,正文和标题显示响应代码400 - 错误的请求。请帮我解决这个问题。