我正在尝试为我的休息响应添加一个内容长度的标题,因为它会回来'chunked'。
@HttpGet
global static RESTBase getCatalog() {
RestRequest req = RestContext.request;
RestResponse resp = RestContext.response;
Map < String, string > respHeader = new Map < String, string > ();
String storeId = req.requestURI.substring(req.requestURI.lastIndexOf('/') + 1);
Store__c currentStore = QueryUtils.getStoreFromStoreNumber(storeId);
if (currentStore == null) {
CatalogResponse catalogResponse = new CatalogResponse();
catalogResponse.Status = '404';
return catalogResponse;
}
Map < String, PricebookEntry > priceBookEntries = getPriceBookEntriesForPriceBook(currentStore.Price_Book__c);
List < TriCom__Category__c > rootCategories = getRootProductCategories();
Map < String, List < UPC_Code__c >> upcCodeMap = getUPCCodeMap();
RESTCatalog catalog = new RESTCatalog();
catalog.PriceBookId = currentStore.Price_Book__c;
catalog.StoreNumber = currentStore.Name;
catalog.Categories = createRestCategory(rootCategories, upcCodeMap, priceBookEntries);
String returnJson = JSON.serialize(catalog);
resp.addHeader('Content-Length', String.valueOf(returnJson.length()));
return catalog;
}
当我收到请求时,我会回来:
"errorCode": "APEX_ERROR",
"message": "System.InvalidHeaderException: Header name \"Content-Length\" is not allowed.\\\n\\\n(System Code)\
感谢任何建议。
答案 0 :(得分:1)
Salesforce将自动设置内容长度。事实证明,无法设置此标头。