grails - Groovy HTTPBuilder POST: missing method(s) -


i'm laying groundwork basic grails app integrates last.fm. i'm stuck on user authentication session key. documentation, sounds simple http post in format have below in code. i've tried every variation of httpbuilder's post , request(post) i've found error out this:

| server running. browse http://localhost:8080/groovylastfm | error 2013-05-14 19:57:10,042 [http-bio-8080-exec-3] error errors.grailsexceptionresolver  - missingpropertyexception occurred when processing request: [get] /groovylastfm/recentsongs/tokenchecker - parameters: token: 452b5619f98e3b66cec11b61940af500 no such property: method class: groovylastfm.user. stacktrace follows: message: no such property: method class: groovylastfm.user line | method ->>   28 | getsession in groovylastfm.user 

i don't know else need import, missing. is grails plugins come in? if so, need include @ app level make httpbuilder work? i'm new grails , not sure merits addition dependencies, or how it. also, i'm on grails 2.1.1 , not using ide. thanks!

package groovylastfm  @grab(group='org.codehaus.groovy.modules.http-builder', module='http-builder', version='0.5.0-rc2' ) import java.security.messagedigest import groovyx.net.http.httpbuilder import static groovyx.net.http.contenttype.* import static groovyx.net.http.method.*  class user { string token string api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" string secret = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"  user (string token) {     this.token = token     getsession() }  def getsession() {     string signature = md5("api_key" + api_key + "methodauth.getsessiontoken" + token + secret)     def postbody = [token:token, api_key:api_key, method:'auth.getsession', api_sig:signature]     def http = new httpbuilder("http://wx.audioscrobbler.com/2.0/")     http.request(method.post) {req->         headers.accept = "application/xml"         requestcontenttype = contenttype.urlenc         body = postbody         response.success { resp,xml->             // read xml response         }     }    } 

i did try basic curl post make sure parameters correct, , did return session key expected:

curl -x post -d "token=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&api_key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx&method=auth.getsession&api_sig=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" http://ws.audioscrobbler.com/2.0/ 

links:

you importing groovyx.net.http.method.* , using method.post, that's why getting no such property: method.

replace with:

http.request(post) { req ->  ... } 

... should do.

alternatively, change import to:

import static groovyx.net.http.method 

and continue using method.post.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -