@RequestMapping(value = "/createItem", method = RequestMethod.POST)
@Override
public void createItem(@RequestParam(value="userId") String userId, @RequestParam(value="title") String title, @RequestParam(value="subtitle") String subtitle, @RequestParam(value="description") String description, @RequestParam(value="category") String category, @RequestParam(value="datapack") String datapack) {
this.itemDAO.createItem(userId, title, subtitle, description, category, datapack);
}
我正在使用Spring创建RESTful应用程序。上面的方法工作正常,但是当数据包长度超过一定长度时,将导致错误。错误说......
解析HTTP请求标头时出错注意:进一步出现HTTP 头部解析错误将记录在DEBUG级别。
我需要将datapack作为参数传递,datapack本身将是一个json文件,我将其转换为字符串。
datapack文件可能非常复杂和庞大。我该如何解决这个问题?
以下是请求的示例:
http://localhost:8090/createItem?userId=test&title=test&subtitle=test&description=test&category=test&datapack=
{
"CLASS": "com.mincom.ellipse.edoi.ejb.menu_item.MENU_ITEMRec",
"INSTANCE": {
"m_creationDate": "20150824",
"m_creationTime": "001616",
"m_creationUser": "SR4187",
"m_lastModDate": "20150824",
"m_lastModTime": "001616",
"m_lastModUser": "SR4187",
"m_menuType": "",
"m_invokationString": "",
"primaryKey": {
"m_uuid": "3b4d95fe3dd3432fb00cde0cc25f903f"
}
}
},
{
"CLASS": "com.mincom.ellipse.edoi.ejb.i18n_descriptions.I18N_DESCRIPTIONSRec",
"INSTANCE": {
"m_creationDate": "20150824",
"m_creationTime": "001616",
"m_creationUser": "SR4187",
"m_lastModDate": "20150824",
"m_lastModTime": "001616",
"m_lastModUser": "SR4187",
"m_description": "CUSTOM_MENU",
"primaryKey": {
"m_locale": "en",
"m_uuid": "3b4d95fe3dd3432fb00cde0cc25f903f"
}
}
},
{
"CLASS": "com.mincom.ellipse.edoi.ejb.top_level_menus.TOP_LEVEL_MENUSRec",
"INSTANCE": {
"m_creationDate": "20150824",
"m_creationUser": "SR4187",
"m_lastModDate": "20150824",
"m_lastModTime": "001620",
"m_creationTime": "001620",
"m_lastModUser": "SR4187",
"m_uuid": "3b4d95fe3dd3432fb00cde0cc25f903f",
"primaryKey": {
"m_name": "SX"
}
}
}
上面的示例有效,但如果我使用较长的JSON文件进行测试,则无效。
答案 0 :(得分:0)
创建一个控制器方法,该方法将接收由$ http服务使用XHR(AJAX)发布的JSON数据
@RequestMapping(value = "/savecompany_json", method = RequestMethod.POST)
public @ResponseBody String saveCompany_JSON( @RequestBody Company company ) {
//
// Code processing the input parameters
//
return "JSON: The company name: " + company.getName() + ", Employees count: " + company.getEmployees() + ", Headoffice: " + company.getHeadoffice();
}
创建一个映射到JSON对象的POJO
public class Company {
private String name;
private long employees;
private String headoffice;
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Long getEmployees() {
return employees;
}
public void setEmployees(Long employees) {
this.employees = employees;
}
public String getHeadoffice() {
return headoffice;
}
public void setHeadoffice(String headoffice) {
this.headoffice = headoffice;
}
}
答案 1 :(得分:0)
如果请求非常大(例如发送文件时),您可能希望更改http标头中的内容类型。例如(虽然根据您实际发送的内容可能会有所不同):
multipart.maxFileSize=3MB
multipart.maxRequestSize=3180KB
然后,如果请求太大而服务器无法接受它,则可能需要扩展请求大小限制。如果您使用的是spring boot,则可以转到application.properties文件(应位于src / main / resources下,但如果它尚不存在,请手动创建)并添加以下属性:
A B K M
1 name current level Max Level Next level cost
6 Soldier 2 4 X
答案 2 :(得分:0)
您无论如何都在使用POST请求,因此只需在内容中发送内容类型为application / x-www-form-urlencoded的参数,就像普通表单提交而不是URL一样。