我一直在试图解决这个问题一段时间,现在我似乎无法使其正常工作。我有一个不接受JSON内容这个POST服务:发布JSON与播放1.2.4
public static void addLifestyleToRecipes(String categoryMappingList) {
Logger.info("In RecipeServices--> addLifestyleToRecipes");
Logger.info("JSON received: %s", categoryMappingList);
Type type = new TypeToken<List<CategoryMapping>>() {
}.getType();
List<CategoryMapping> categoryMapping = new Gson().fromJson(categoryMappingList, type);
for (CategoryMapping cat : categoryMapping) {
//the rest is irrelevant to the problem
}
当我测试方法与functionnal测试,一切正常:
List<CategoryMapping> list = new ArrayList<CategoryMapping>();
list.add(new CategoryMapping(MULTI_LANG_ID, recipes));
list.add(new CategoryMapping(MULTI_LANG_ID, recipes));
String body = new Gson().toJson(list);
Map<String, String> params = new HashMap<String, String>();
params.put("categoryMappingList", body);
StringBuffer url = TestHelper.generateBaseUrl(apiKey, apiVersion);
url.append("/recipes/add/categories");
Response response = POST(url, params);
问题是当我尝试实际调用服务,我的参数“categoryMappingList”始终为空。我也尝试使用Chrome的“高级休息客户端”来模拟POST请求,但我总是得到相同的结果。
我还注意到,如果我指定我的Content-Type是“application/json; charset = utf-8”之外的任何东西,则会出现403错误。
任何线索?
谢谢。
您可以添加调用服务的客户端代码 –