【发布时间】:2012-08-19 12:57:03
【问题描述】:
我正在使用 Rest Assured 测试 REST api。尝试使用 url 和正文内容中的参数进行 POST 时遇到错误。这在手动测试时可以正常工作。从 url 中删除参数不是一个选项
测试代码:
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);
运行时会抛出以下错误
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)
...
为什么 Rest Assured 不允许在 POST 中同时使用参数和正文内容?
【问题讨论】:
-
我使用的是比较老的 Rest Assured 1.1.6。但是,查看github 上的代码,这似乎仍然是个问题
-
我不知道你可以有 Post 参数和 body,所以 Rest Assured 的创建者可能也没有。您是否尝试过自己构建 Rest Assured 并注释掉此检查?
标签: java rest rest-assured