我正在编写一个测试程序来测试jersey客户端是否具有json主体。我收到邮递员的响应,并尝试从Java jersey客户端调用它,但由于报错
java.lang.IllegalStateException: Entity must be null for http method DELETE.
我如何在Jersey中请求删除带有json正文的终结点。
我尝试了以下客户端:
import javax.ws.rs.client.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
public class First {
public static void main(String[] args) {
String str = "{\n" +
"\t\"ecid\": \"1\",\n" +
"\t\"customerModelKey\": \"195000300\",\n" +
"\t\"customerModelName\": \"A\",\n" +
"\t\"customerGroupCode\": \"BI\"\n" +
"}";
System.out.println("test");
Client client = ClientBuilder.newClient();
WebTarget webTarget
= client.target("http://localhost:9092/");
WebTarget employeeWebTarget
= webTarget.path("deletemodelecidrel");
Invocation.Builder invocationBuilder
= employeeWebTarget.request(MediaType.APPLICATION_JSON);
Invocation invocation
= invocationBuilder.build("DELETE",Entity.text(str));
Response response = invocation.invoke();
System.out.println(response);
}
}
泽西岛禁止发送带有DELETE请求的数据。
如果确实需要这样做,则可以按以下方式配置客户端:
ClientConfig clientConfig = new ClientConfig();
clientConfig.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
Client client = ClientBuilder.newClient(clientConfig);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句