實際上我正在從一個play應用程序重定向到另一個play應用程序,最後我收到響應作爲Result對象..下面是兩個應用程序中的操作。我正在從apllication1重定向到application2。應用程序2將返回JSON字符串,我需要提取。如何在play應用程序中從play.mvc.Result對象中提取結果內容?
如何從Result對象中檢索JSON內容?
應用1:
public static Result redirectTest(){
Result result = redirect("http://ipaddress:9000/authenticate");
/*** here I would like to extract JSON string from result***/
return result;
}
應用2:
@SecuredAction
public static Result index() {
Map<String, String> response = new HashMap<String, String>();
DemoUser user = (DemoUser) ctx().args.get(SecureSocial.USER_KEY);
for(BasicProfile basicProfile: user.identities){
response.put("name", basicProfile.firstName().get());
response.put("emailId", basicProfile.email().get());
response.put("providerId", basicProfile.providerId());
response.put("avatarurl", basicProfile.avatarUrl().get());
}
return ok(new JSONObject(response).toString());
}
JavaResultExtractor.getBody(結果,0L)給出超時即使我把它從0更改爲100K – 2016-09-14 11:58:39
想知道爲什麼不要使用play.test.Helpers.contentAsString(result)? – Fahad 2017-03-28 17:16:10
助手類具有測試範圍。 – 2017-03-28 20:56:02