我正在尝试通过伪装客户端调用api,并通过MultipartFile将该文件以及一些字符串参数上传。
这是我的客户代码:
package com.abc;
import feign.codec.Encoder;
@FeignClient(url = "https://xys.com", name = "uploadfile", configuration = UploadFileFeign.MultipartSupportConfig.class)
public interface UploadFileFeign {
@PostMapping(value = "leaveApplication", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ObjectRestResponse<?> handleFileUpload(@RequestParam(value = "request") String request,
@RequestPart(value = "file") MultipartFile srcFile);
class MultipartSupportConfig {
@Bean
public Encoder feignFormEncoder() {
return new FeignSpringFormEncoder();
}
@Bean
public feign.Logger.Level multipartLoggerLevel() {
return feign.Logger.Level.FULL;
}
}
}
下面是我的客户端正在调用的API代码。
@RequestMapping(value="/services/leaveApplication", method=Request.POST, produces = MediaType.MULTIPART_FORM_DATA_VALUE, headers="Accept=application/json")
public ResponseOutput leaveApplication(@RequestParam("request") String request, @RequestParam(value = "file", required=false) MultipartFile srcFile) throws Exception {
}
但是我在响应中遇到错误: 403-禁止的错误。 您无权访问/ services / leaveApplication
其他不涉及文件上传的api都可以正常工作。
答案 0 :(得分:0)
这里有错字:
请求映射URL为:/services/leaveApplication
但是您正在访问:/service/leaveApplication
将service
更改为services