2013-05-15 35 views
4

我正在爲我的應用程序編寫webservices。 我的問題是,當我把它用它的工作原理GET方法,但是當我使用POST方法PARAMS不包含我的參數的螞蟻:當我調用Grails上的Post方法時,參數爲空

當我打電話使用GET,這是則params的內容:

params : [username:azerty, test:test, param2:param2, action:editProfile, controller:userWebService] 

當我打電話使用POST,這是則params的內容:

params : [action:editProfile, controller:userWebService] 

編輯:

/* user controller */ 
"/service/$action?"(controller: "userWebService", parseRequest: true) 

UserWebServiceController

.... 
static allowedMethods = [editProfile:['POST', 'GET']] 
.... 
def editProfile(){ 

    println "params : "+ params 
.... 
} 

測試我使用REST控制檯插件在Chrome

enter image description here

+0

'UrlMapping'是怎麼樣的? – dmahapatro

+0

你可以分享這個帖子的代碼嗎? –

+0

我編輯了問題 –

回答

4

paramsPOST請求不發送作爲查詢字符串不像GET。在請求POST的情況下,參數字符串必須嵌入請求正文中。

使用content-typeapplication/x-www-form-urlencoded

,並在request-body使用
username=azerty&test=test

你應該能夠看到params裏面的參數控制器。

enter image description here

你應該能夠看到
params : [age:25, name:Hamila, action:editProfile, controller:userWebService]

,我讓你在測試中看起來更年輕? :)

+0

謝謝@dmahapatro,它現在可以工作:),不,你讓我老了:我是24:p,再次感謝 –

+0

大聲笑。下次我會記住這一點。 :) – dmahapatro

相關問題