【问题标题】:How to invoke webservice defined in grails application from php如何从 php 调用在 grails 应用程序中定义的 web 服务
【发布时间】:2013-03-30 07:13:57
【问题描述】:

我是网络服务的新手

我的应用中有一个域类,如下所示。

class Training{

  string name
  Date date

}

我想在 php 页面中显示培训列表

我必须在 grails 和 php 脚本中进行哪些更改才能做到这一点。我想要 JSON 格式的数据。

而且我想遵循 RESTful 架构。

基本上我想从我的网站(用 php 编写)与 grails 应用程序进行交互。将来我想将数据从我的网站保存到 grails 应用程序数据库和许多调用中。

在 web 服务中提供请求之前,我是否需要进行身份验证。

【问题讨论】:

  • the Grails documentation 中介绍了在 Grails 中创建 Web 服务。调用 Web 服务是发出 Web 请求,并不依赖于实现 Web 服务的框架。最后,是否进行身份验证是基于您的安全需求的设计决策。

标签: php web-services rest grails


【解决方案1】:

如果您想遵循架构模式,请参阅以下链接:http://grails.org/doc/latest/guide/webServices.html#REST

首先创建您的 TrainingController 控制器,该控制器执行请求的操作并返回 json 数据。例如

class TrainingController {
   def show = {
      render Training.get(params.long('id')) as json
   }
}

如果你不使用特殊的 url 映射来匹配 restful 模式,你可以简单地调用 training/1 并返回 json 结构。有关更多渲染选项,请参阅文档。

【讨论】:

  • 如何远程调用 grails webservice 方法意味着在 grails 应用程序之外使用来自另一台服务器的 jquery 和 html
  • 如果您想使用 jquery 从另一台服务器调用此控制器操作,我建议使用 jquery.ajax() 函数。见:api.jquery.com/jQuery.ajax.
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2013-03-30
  • 1970-01-01
  • 2012-11-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-19
相关资源
最近更新 更多