[英]HTTP Post request with content type application/x-www-form-urlencoded not working in Spring boot service
[英]Http Put request with content type application/x-www-form-urlencoded not working in Spring
我有一个spring-boot应用程序,它唯一要做的就是接收http请求。
这是我的春季自助餐:
@RestController
public class WebController {
@Autowired
private CallRecording callRecording;
@PutMapping(path = "/cdrpostbox/callrecording/{hostedAccountId}/{mp3FileName}", consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
public ResponseEntity<Object> callRecording(@PathVariable("hostedAccountId") String hostedAccountId, @PathVariable("mp3FileName") String mp3FileName, MultipartFile file) {
return ResponseEntity.status(callRecording.service(hostedAccountId, mp3FileName, file)).body(null);
}
}
我正在使用邮递员发送请求。 我的spring应用程序收到的请求无法更改,因为我的团队未维护代码。
我在这里发现了很多类似问题的问题,但不是必须解决的问题。 我尝试添加和删除@RequestBody ,将@RequestBody替换为@RequestParam ,尝试了MultiValueMap ,但它始终返回相同的错误。
java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "x"
我什至无法调试代码,因为它在到达控制器之前就失败了。
我想念什么?
标头中的content-type是urlencoded,但是您发送二进制数据。
-编辑
如果要以MultipartFile形式获取文件,则从邮递员以表单数据形式发送文件,将数据名称设置为file并将@RequestParam
添加到方法中的file参数。
经过更多调查后,我找到了解决方案。
@RestController
@EnableWebMvc
public class WebController {
@Autowired
private CallRecording callRecording;
@PutMapping(path = "/cdrpostbox/callrecording/{hostedAccountId}/{mp3FileName:.+}")
public ResponseEntity<Object> callRecording(@PathVariable("hostedAccountId") String hostedAccountId, @PathVariable("mp3FileName") String mp3FileName, @RequestBody byte[] requestBody) {
return ResponseEntity.status(callRecording.service(hostedAccountId, mp3FileName, requestBody)).body(null);
}
它缺少@EnableWebMvc
。 我还更改了映射{mp3FileName:.+}
因为它已截断了请求的结尾,您可以在此处检查SO问题。
感谢@Selindek的帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.