简体   繁体   English

如何使用球衣客户端(RestFull)读取数据以响应POST操作

[英]How to read data in response of POST operation using jersey client (RestFull)

In my java client application, I am accessing a endpoint URL and could able to get response back, but it is in HTML code!. 在我的Java客户端应用程序中,我正在访问终结点URL,并且能够获取响应,但是它是HTML代码!

Method : Post 方法:张贴

resource.accept(MediaType.APPLICATION_JSON_TYPE);

WebResource resource = Client.create().resource(
                communicatorVO.getTargetURL());
String **response** = resource.queryParams(communicatorVO.getFormData()).type(MediaType.APPLICATION_JSON_TYPE).post(String.class, gson.toJson(communicatorVO.getRequestObject()));

The response object always contains HTML code! 响应对象始终包含HTML代码! How to get the actual data? 如何获得实际数据?

If I try using chrome restful client, am getting below response. 如果我尝试使用chrome restful客户端,则会收到以下响应。

{ "access_token" : "YOUR_NEW_ACCESS_TOKEN", "token_type" : "bearer", "expires_in" : 10800, "refresh_token" : "YOUR_REFRESH_TOKEN", "scope" : "write read offline_access" } {“ access_token”:“ YOUR_NEW_ACCESS_TOKEN”,“ token_type”:“ bearer”,“ expires_in”:10800,“ refresh_token”:“ YOUR_REFRESH_TOKEN”,“ scope”:“写入读取线下访问”}

This issue has been resolved. 此问题已得到解决。

I added type & accept in single line and it started returning expected json response. 我在单行中添加了type&accept,它开始返回预期的json响应。 Now I can parse the json into any java object. 现在,我可以将json解析为任何java对象。

Code : 代码:

response = resource.type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).accept(MediaType.APPLICATION_JSON_TYPE).post(ClientResponse.class, communicatorVO.getFormData());;

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

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