Tôi đang thử nghiệm một REST api bằng Rest Restured. Tôi đang gặp lỗi khi cố gắng POST với cả tham số trong url và nội dung nội dung. Điều này hoạt động chính xác khi kiểm tra thủ công. Loại bỏ tham số hình url không phải là một lựa chọnPhần còn lại được bảo đảm - không thể POST với các tham số và nội dung
Mã kiểm tra:
String endpoint = http://localhost:8080/x/y/z/id?custom=test;
String body = "[{\"boolField\":true,\"intField\":991},
{\"boolField\":false,\"intField\":998}]";
expect().spec(OK).given().body(body).post(endpoint);
nào ném được lỗi sau khi chạy
You can either send parameters OR body content in the POST, not both!
java.lang.IllegalStateException: You can either send parameters OR body content in the POST, not both!
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:39)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
at org.codehaus.groovy.reflection.CachedConstructor.invoke(CachedConstructor.java:77)
at org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor(ConstructorSite.java:102)
at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callConstructor(AbstractCallSite.java:198)
at com.jayway.restassured.internal.RequestSpecificationImpl.sendRequest(RequestSpecificationImpl.groovy:282)
at com.jayway.restassured.internal.RequestSpecificationImpl.this$2$sendRequest(RequestSpecificationImpl.groovy)
at com.jayway.restassured.internal.RequestSpecificationImpl$this$2$sendRequest.callCurrent(Unknown Source)
at com.jayway.restassured.internal.RequestSpecificationImpl.post(RequestSpecificationImpl.groovy:83)
...
Tại sao yên tâm không cho phép cả hai thông số và nội dung cơ thể một POST?
Im sử dụng yên tâm 1.1.6, mà là khá cũ. Tuy nhiên, hãy xem mã trên [github] (https://github.com/jayway/rest-assured/blob/master/rest-assured/src/main/groovy/com/jayway/restassured/internal/RequestSpecificationImpl.groovy) điều này vẫn có vẻ là một vấn đề –
Tôi không biết bạn có thể có thông số Đăng bài và nội dung nên có thể những người sáng tạo của Rest Assured cũng vậy. Bạn đã thử xây dựng phần còn lại Đảm bảo bản thân và bình luận ra kiểm tra này? – mercutio
đã tạo sự cố để yên tâm: http://code.google.com/p/rest-assured/issues/detail?id=196&thanks=196&ts=1346105863 –