如何使用HTTP builder助手插件grails 3调用http()? [英] how to call withHttp() with http builder helper plugin grails 3?

查看:155
本文介绍了如何使用HTTP builder助手插件grails 3调用http()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图将我的项目从grails 2.1.1升级到grails 3.0.9



在grails 3.0.9中:我像这样安装了这个插件..

  compile'org.grails.plugins:http-builder-helper:1.0.2'

我运行它...



我得到这个错误..

p>

 错误com.akiong.SmsService  - 没有方法签名:
com.akiong.SmsService.withHttp()适用于参数类型:
(java.util.LinkedHashMap,com.akiong.SmsService $ _sendSms_clos ure2)values:
[[uri:https://abc.web.id],com.akiong.SmsService $ _sendSms_closure2 @ 48d98154]
groovy.lang.MissingMethodException:无方法签名:
com.akiong.SmsService.withHttp()适用于参数类型:
(java.util.LinkedHashMap,com .akiong.SmsService $ _sendSm s_closure2)values:
[[uri:https://abc.web.id],com.akiong.SmsService$_sendSms_closure2@48d98154]

这是我的代码com.akion g.SmsService.groovy

  withHttp(uri:uri){
client.getParams()。setBooleanParameter(http .protocol.expect-continue,false)
get(path:'/abc.php',query:[u:smsMaskingUser,p:smsMaskingPassword,d:destinationNo,m:messages]){resp,reader - >
loggResponse(resp,reader,refNo)
}
}

我必须做什么?



我试过这两个:

compile' org.grails.plugins:http-builder-helper:1.0.0





compile'org.grails.plugins:grails-http-builder-helper:1.0.0'



这两个都可以下载...但是我得到的是同样的错误我改变了我的代码从grails 2中解决方案

> 3,而不是在grails 3上使用http-builder-helper插件,但是我的应用程序使用了http-builder-helper plugin.grails 2这样的。

  import groovyx.net.http.HTTPBuilder 
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT
code>

和这个

  http .request(GET,TEXT){req  - > 
uri.path ='/api.php'//覆盖默认URL中的任何路径
uri.query = [u:yourusername,p:yourpassword,d:something,m:messages]
// headers.'User-Agent'='Mozilla / 5.0'

response.success = {resp,reader - >
assert resp.status == 200
loggResponse(resp,reader,refNo)
}

//仅为404(未找到)状态码调用:
response.'404'= {resp - >
println'找不到'
}
}

会帮助你

i am trying to upgrade my project from grails 2.1.1 to grails 3.0.9

in grails 3.0.9 : i install this plugin like this..

compile 'org.grails.plugins:http-builder-helper:1.0.2'

and i run it...

i get this error..

    ERROR com.akiong.SmsService - No signature of method: 
com.akiong.SmsService.withHttp() is applicable for argument types: 
(java.util.LinkedHashMap, com.akiong.SmsService$_sendSms_clos ure2) values: 
[[uri:https://abc.web.id], com.akiong.SmsService$_sendSms_closure2@48d98154] 
groovy.lang.MissingMethodException: No signature of method: 
com.akiong.SmsService.withHttp() is applicable for argument types: 
(java.util.LinkedHashMap, com.akiong.SmsService$_sendSm s_closure2) values: 
[[uri:https://abc.web.id], com.akiong.SmsService$_sendSms_closure2@48d98154]

this is my code com.akiong.SmsService.groovy

withHttp(uri: uri) {
                    client.getParams().setBooleanParameter("http.protocol.expect-continue", false)
                    get(path: '/abc.php', query: [u: smsMaskingUser, p: smsMaskingPassword, d: destinationNo, m: messages]){ resp, reader ->
                        loggResponse(resp, reader, refNo)
                    }
                }

what must i do?

i tried both of this :

compile 'org.grails.plugins:http-builder-helper:1.0.0'

and

compile 'org.grails.plugins:grails-http-builder-helper:1.0.0'

both of this can be download...but i get the same error

解决方案

i change my code from grails 2 -> 3 and not use http-builder-helper plugin on grails 3, but my app with grails 2 using http-builder-helper plugin.like this.

import groovyx.net.http.HTTPBuilder
import static groovyx.net.http.Method.GET
import static groovyx.net.http.ContentType.TEXT

and this

http.request(GET,TEXT) { req ->
                uri.path = '/api.php' // overrides any path in the default URL
                uri.query = [ u: yourusername, p: yourpassword, d: something, m: messages ]
//              headers.'User-Agent' = 'Mozilla/5.0'

                response.success = { resp, reader ->
                    assert resp.status == 200
                    loggResponse(resp, reader, refNo)
                }

                // called only for a 404 (not found) status code:
                response.'404' = { resp ->
                    println 'Not found'
                }
            }

hope this will help you

这篇关于如何使用HTTP builder助手插件grails 3调用http()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆