Java 中的 JSON 代理 / 玩吧!框架
我有一个游戏!应用程序和 JavaScript 我们现在遇到了同源策略问题。
我想要的是 JavaScript ajax 调用转到我们自己的服务器,并且该服务器再次将 json 调用路由到外部 REST API。
我的 JavaScript 使用 ajax 访问此 url:
$.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);
}
并返回响应?
或者可以通过直接重新路由来动态完成吗?
I have a Play! application and from the JavaScript we now have run in to the Same Origin Policy Problem.
What I want is that JavaScript ajax calls go to our own server and that this server again route the json call to the external REST API.
My JavaScript use ajax to this url:
$.getJSON("http://mydomain.com/users", function(users) {
//callback
});
How can I easly make the server route to lets say:
public void getUsers(){
// result = call www.otherdomain.org/api/users.json What to do here?
renderJson(result);
}
and the return the response?
Or can it be done dynamically somewhere by directly rerouting?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这里有一个执行异步 http 调用的示例(例如 facebook api)
here comes an example for doing async http calls (e.g. to facebook api)
您可以使用 WS 类 调用另一个URL 作为 Web 服务并检索答案。
请参阅此处的示例
You can use the WS class to call another URL as a web service and retrieve the answer.
See an example here