java - Java/Play 中的 JSON 代理!框架

标签 java javascript json playframework same-origin-policy

我有戏!应用程序和我们现在运行的 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/

相关文章:

java - JAVA 中的守护进程线程组是什么?

javascript - 在 json、node.js 中查找对象的值

javascript - 在 textarea 的输出 div 中保留换行符

python - 将 json 文本作为命令行参数传递

javascript - 如何确定 JSON 中字段的数据类型

java - 如何从 Firestore Android 中的集合中获取文档列表

java - 在方法中使用 awt.Graphics

JAVA。我收到 'unreported exception' 编译器错误

javascript 按钮 当选择某个值时,如何从所有按钮中删除一个类?

javascript - ESLint 意外悬空 '_' 中的 '__place' 无下划线悬空