我有戏!应用程序和我们现在运行的 JavaScript 中的同源策略问题。
我想要的是 JavaScript ajax 调用转到我们自己的服务器,并且该服务器再次将 json 调用路由到外部 REST API。
我的 JavaScript 对此 url 使用 ajax:
$.getJSON("http://mydomain.com/users", function(users) {
//callback
});
我怎样才能轻松地让服务器路由到让我们说:
public void getUsers(){
// result = call www.otherdomain.org/api/users.json What to do here?
renderJson(result);
}
然后返回响应?
还是可以通过直接重新路由在某处动态完成?
最佳答案
这里有一个进行异步 http 调用的例子(例如到 facebook api)
WSRequest req = WS.url("https://graph.facebook.com/100001789213579");
Promise<HttpResponse> respAsync = req.getAsync();
HttpResponse resp = await(respAsync);
JsonElement jsonResp = resp.getJson();
JsonObject jsonObj = new JsonObject();
jsonObj.add("facebook-response", jsonResp);
renderJSON(jsonObj);
关于java - Java/Play 中的 JSON 代理!框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8183199/