简体   繁体   English

Restlet向服务器发送“获取”请求并处理响应

[英]Restlet send “get” request to server and process response

I would like to send a get request to a remote server using Restlet and receive the response (as Json ). 我想使用Restletget请求发送到远程服务器并接收响应(作为Json )。

Here is my starting point, please feel free to complete: 这是我的出发点,请随时完成:

ClientResource cr = new ClientResource("https://"+url);

JsonRepresentation r = (JsonRepresentation) cr.get();

r.getJsonObject().get("MY_VALUE");

Restlet version 2.1.7 Restlet版本2.1.7

Json : {"title":"General Terms & Conditions","version":"20022014_001"} 杰森{"title":"General Terms & Conditions","version":"20022014_001"}

In fact, you don't use the JsonRepresentation the right way. 实际上,您没有正确使用JsonRepresentation The method get of the class ClientResource doesn't return an element of such type. ClientResource类的get方法不会返回此类元素。 You must use it as described below: 您必须按照以下说明使用它:

ClientResource cr = new ClientResource("https://"+url);
Representation repr = cr.get();
JsonRepresentation jsonRepr = new JsonRepresentation(repr);

String value = jsonRepr.getJsonObject().get("MY_VALUE");

Hope it helps you, Thierry 希望对您有帮助,蒂埃里

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

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