简体   繁体   English

为什么在使用Jersey客户端的POST呼叫中出现400错误代码

[英]Why 400 error code in POST call using Jersey client

I am calling a post request using Jersey rest client which contains no request body but contains authorization header. 我正在使用Jersey rest客户端调用发布请求,该客户端不包含请求主体,但包含授权标头。 I am always getting 400 error. 我总是收到400错误。 I tried from postman i got 200 response. 我从邮递员那里试过,得到200条回应。 Here is my code 这是我的代码

ClientResponse response = null;
Client cliente=Client.create();
cliente.addFilter(new LoggingFilter(System.out));
WebResource webResource=cliente.resource("https://URL/token");
Builder builder = webResource.accept("application/json");
builder.type(MediaType.APPLICATION_JSON);
builder.header("Authorization", "Basic YbjjkwliOTQtNjRiYy00NWE5LWFhMzQtMTFhNDkyZZjNTVlOjZjYjk2OTMwNGE5YTQ3OTlhODVjZTM5MDFiMDEyMTI2";
builder.post(ClientResponse.class,Entity.json(""));

Don't use the way you are trying right now. 不要使用您现在尝试的方式。 Use HttpAuthenticationFeature from Jersey like this 像这样使用来自Jersey的HttpAuthenticationFeature

HttpAuthenticationFeature feature = HttpAuthenticationFeature.basic("username", "password");

 

final Client client = ClientBuilder.newClient();

client.register(feature);

If you are getting 200 success respone in postman and failure response in your application then you need to check your api with another api tester online tool. 如果您在应用程序中获得200个成功的邮递员响应和失败响应响应,那么您需要使用另一个api测试仪在线工具来检查您的api。 I had the same issue i put / at the last of end point. 我在终点的最后有一个相同的问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM