【问题标题】:How to recieve an HTTPS Post request in Grails?如何在 Grails 中接收 HTTPS Post 请求?
【发布时间】:2012-06-13 20:31:02
【问题描述】:

我正在编写一个需要将数据传递给基于 Grails 的 Web 应用程序的 Android 应用程序。我想在客户端使用 Post 请求。我不确定在服务器端从哪里开始。我知道我可能应该使用看起来像这样的代码:request.getParams() 但我不确定这需要去哪里。有什么建议吗?

【问题讨论】:

    标签: android http grails


    【解决方案1】:

    您需要创建一个controller。例如

    FooController {
        def index = {
            if (request.status == 'POST')
                print request.params
            }
        }
    }
    

    现在发帖子到http://<url context>/foo/index

    【讨论】:

      【解决方案2】:

      在服务器端,无论请求是使用 HTTP 还是 HTTPS、GET 还是 POST,您的代码都是相同的。从控制器开始:

      class TestController {
          def index() {
              // params is a map with all the request parameters
              println params
      
              // do your server side stuff here
          }
      }
      

      对于开发,请将您的 android 应用程序发布到 http://<devserver>:8080/<appname>/test。部署到生产环境时,更改 URL https://<prodserver>/<appname>/test

      如果您想在开发中使用 HTTPS,您可以使用 grails run-app -https 运行开发服务器,grails 将自动创建自签名 SSL 证书并侦听端口 8443 上的 HTTPS 连接以及通常的 HTTP 服务器在 8080 端口上。

      【讨论】:

        猜你喜欢
        • 2018-10-04
        • 2023-03-16
        • 1970-01-01
        • 2016-03-01
        • 2015-09-15
        • 2011-04-14
        • 2012-02-03
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多