【问题标题】:How to use Groovy to access simple web service?如何使用 Groovy 访问简单的 Web 服务?
【发布时间】:2013-04-02 23:46:13
【问题描述】:

我绝对是网络服务方面的菜鸟。我正在尝试使用 groovy 作为客户端来访问一个简单的 Web 服务。 Web 服务具有基本身份验证并使用 https。在浏览器中,我会使用这样的东西:

https://myserver.com/app/services/soap/call?script=MyService&username=me&password=secret

我如何从 groovy 中调用它?我试图弄清楚如何使用 groovy-wslite,但我无法弄清楚(我知道如何使用 URL 进行服务......不知道所有这些正文和标题......等等......是或者它与我知道的 url 的关系如何工作)。我还尝试使用真正简单的 http 类型的调用:

'https://myserver.com/app/services/soap/call?script=MyService&username=me&password=secret'.toURL().text

但这没有用。是否有捷径可寻?

谢谢!

【问题讨论】:

    标签: web-services groovy


    【解决方案1】:

    我在发布后立即意识到问题可能与 SSL 和自签名证书有关。我找到了这篇文章:

    http://java.dzone.com/articles/reading-https-url-self-signed

    使用这个库的:

    https://github.com/kevinsawicki/http-request

    然后解决方案变得非常简单:

    def req = 'https://myserver.com/app/services/soap/call?script=MyService&username=me&password=secret'
    req = HttpRequest.get(req)
    req.trustAllCerts()
    req.trustAllHosts()
    println(req.body())
    

    我确信有更好的方法可以做到这一点,但这对我有用。 :D

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2023-04-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-04
    • 1970-01-01
    相关资源
    最近更新 更多