栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

删除POST请求中的Transfer-Encoding:chunked?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

删除POST请求中的Transfer-Encoding:chunked?

您可以用来

ResponseEntity
显式设置标题。棘手的一点是弄清楚您的内容实际上有多长时间:

@RequestMapping(value = "/contacts", method = RequestMethod.POST)public ResponseEntity<Map<String, ContactInfo>> addContactInfo(@RequestBody Map<String, ContactInfo> contactInfoDto) throws JsonProcessingException {    ContactInfo contactInfo = contactInfoDto.get("contact");    if (contactInfo == null) {        throw new IllegalArgumentException("Contact not found.");    }    contactInfo = this.contactInfoManager.addNew(contactInfo);    Map<String, ContactInfo> map = new HashMap<>();    map.put("contact", contactInfo);    HttpHeaders headers = new HttpHeaders();    headers.set(HttpHeaders.CONTENT_LENGTH, String.valueOf(new ObjectMapper().writevalueAsString(map).length()));    return new ResponseEntity<Map<String, ContactInfo>>(map, headers, HttpStatus.CREATED);}

测试:

$ curl -v http://localhost:8080/contacts/ -X POST -d '{ "contact": { "name": "foo" } }' -H 'Content-Type: application/json' && echo*   Trying ::1...* Connected to localhost (::1) port 8080 (#0)> POST /contacts/ HTTP/1.1> Host: localhost:8080> User-Agent: curl/7.43.0> Accept: */*> Content-Type: application/json> Content-Length: 32> * upload completely sent off: 32 out of 32 bytes< HTTP/1.1 201 Created< Server: Apache-Coyote/1.1< X-Application-Context: application< Content-Type: application/json;charset=UTF-8< Content-Length: 26< Date: Fri, 10 Jun 2016 13:24:23 GMT< * Connection #0 to host localhost left intact{"contact":{"name":"foo"}}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/412153.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号