2015-02-23 170 views
0

我想用Restlet向远程服务器发送get请求并接收响应(如Json)。Restlet向服务器发送“get”请求并处理响应

这里是我的起点,请随时来完成:

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

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

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

的Restlet版本2.1.7

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

+0

这很难像猜测;-)你我的异常堆栈跟踪可能吗?谢谢! – 2015-02-23 16:29:43

+0

这是挂断。 它落在'ClassCastException'上。 所以很明显,转换到'JsonRepresentation'不是答案。 – Igor 2015-02-23 16:39:40

回答

1

事实上,你不以正确的方式使用JsonRepresentation。类ClientResource的方法get不会返回此类型的元素。你必须使用它,如下所述:

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

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

希望它可以帮助你, 蒂埃里

+0

我会尝试一下,让你知道。 感谢您的答复 – Igor 2015-02-23 16:57:59

+0

嗯,它没有工作。 它落在'org.json.JSONException:在循环屏障上被阻塞的线程已超时。' – Igor 2015-02-23 17:05:37

+0

转而使用** apache **的'HttpClient'。它似乎做的工作。 – Igor 2015-02-24 06:44:13

相关问题