grails-plugins / grails-rest-client-builder

REST client plugin that uses Spring's RestTemplate
http://grails.org/plugin/rest-client-builder
Apache License 2.0
65 stars 32 forks source link

question: how to do a regular post like a web form #18

Closed gpinkham closed 11 years ago

gpinkham commented 11 years ago

I'm assuming I'm doing something wrong here..

I'm calling an API that is out of my control and is written in Cold Fusion (shiver). When I send the request like this:

    def resp = rest.post("${baseUrl}/rest/v1/ValidateUser") {
      accept MediaType.ALL.toString(), MediaType.APPLICATION_JSON.toString()
      body StudyId: studyId, siteId: siteId, UN: username,  PW: password

I get a 500 returned and the CF develop said I didn't post/submit any form variables.. his unit test work fine (both using cold fusion to call it and posting standard web based html forms).... Hence my guessing this isn't doing a form post.. Seems like it's just sending a body full of JSON text..

DEBUG client.RestTemplate  - Writing [{StudyId=xxx, siteId=xxxx, UN=sxxxx, PW=xxxxx}] using [org.springframework.http.converter.json.MappingJackson2HttpMessageConverter@5c30cf7d]

Thanks!!!!

gpinkham commented 11 years ago

ok.. figured this out.. dug deeper into the code than I did last time.. changed it to this and now it accepts the post...

    def resp = rest.post("${baseUrl}/rest/v1/ValidateUser") {
      accept MediaType.ALL.toString(), MediaType.APPLICATION_JSON.toString()
      setProperty('StudyId',studyId)
      setProperty('siteId',siteId)
      setProperty('UN',username)
      setProperty('PW',password)
    }