2013-07-30 78 views
0

我是使用REST服務的新手,我正在使用apigee.com測試GET和POST請求以獲得我的REST服務。使用apigee消費REST服務

我的問題是,如何通過傳遞參數來創建新記錄來測試我的POST請求?

我可以成功運行我的GET請求,然後返回帶有請求記錄的JSON響應。

當我嘗試我的職務的請求,我得到一個錯誤:

"message": "Content-Type header specified in HTTP request is not supported: application/x-www-form-urlencoded; charset=UTF-8", 
"errorCode": "UNSUPPORTED_MEDIA_TYPE" 

這裏是我的類方法:

@HttpPost 
global static Merchandise createMerchandise(String name, String description, Double price, Integer totalInventory) { 
    System.Debug('POST /merchandise/*'); 

    Merchandise__c merchandise = new Merchandise__c(); 
    merchandise.Name = name; 
    merchandise.Description__c = description; 
    merchandise.Price__c = price; 
    merchandise.Total_Inventory__c = totalInventory; 

    insert merchandise; 

    Merchandise merch = castToMerchandise(merchandise); 

    return merch; 
} 

我如何通過在URL中的參數和怎麼做我使用agigee控制檯指定正確的內容類型來測試我的服務?

感謝您的任何幫助。

回答

0

如果您要繼續使用它將有效載荷發送到URL,您應該查看您正在接受Rest服務的格式並添加「x-www-form-urlencoded」。

您可以在Apigee控制檯的Headers選項卡下指定Content-Type,只需要查看服務器接受的Content-Type。

要傳遞url中的參數,您只需將?附加到Url的末尾並放置變量名稱和值。這些通常被稱爲queryStrings 像這樣:

www.example.com?name=Dman100 & Rep = 104。

這個例子將傳遞給變量名和Rep當在URL中傳遞變量時,你必須小心地將html url編碼爲變量及其值。

對於您發送有效內容/正文內容的帖子。無論什麼格式都是必要的。

+0

我似乎無法添加任何參數/值到我的REST服務apigee控制檯中的標題,模板或正文。如果我使用GET請求並運行:'https:// c16.salesforce.com/services/apexrest/Account/001f0000007qcD5',我會得到一個成功的響應。但是,如果我嘗試運行POST請求,我不能在Body,Header或Template中輸入任何參數? – Dman100

+0

您是否使用apigee的通用api控制檯? – CBIII

+0

這是我使用的網址'https://apigee.com/console/salesforce' – Dman100