不支持方法'POST'405
问题描述:
我有一个POST
上传文件的方法。为上传文件上一通Token
我header
不支持方法'POST'405
private RessourceMetadata doSave(Ressource ressource) throws IOException, FileNotFoundException {
String tempFilePath = writeDocumentToTempFile(ressource);
MultiValueMap<String, Object> parts = createMultipartFileParam(tempFilePath);
RessourceMetadata ressourceMetadata = getRestTemplate().postForObject(
getServiceUrl()
+ "/uploadFileProperties?group={group}&projectId={projectId}&version={version}&env={env}",
parts, RessourceMetadata.class, ressource.getGroup(), ressource.getId(), ressource.getVersion(),
ressource.getEnv());
return ressourceMetadata;
}
....
private MultiValueMap<String, Object> createMultipartFileParam(String tempFilePath) {
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<String, Object>();
parts.add("file", new FileSystemResource(tempFilePath));
parts.add("Authorization", "hrYIwyXoKGkY2juJfJb012Qx768RtUYA");
return parts;
}
错误:
o.s.w.s.PageNotFound - Request method 'POST' not supported
2017-Jun-15 09:50:31.852 ERROR [main] f.g.d.d.w.c.ServiceClient - Error while uploading file
org.springframework.web.client.HttpClientErrorException: 405 Method Not Allowed
什么是错我的代码?
POST方法:
@RequestMapping(value = "/uploadFileProperties", method = RequestMethod.POST)
@ResponseStatus(HttpStatus.OK)
@ApiImplicitParams({
@ApiImplicitParam(name = "Authorization", value = "Authorization token", required = true, dataType = "string", paramType = "header") })
public @ResponseBody RessourceMetadata uploadProperties(
@ApiParam(name = "file", value = "fichier properties à uploader", defaultValue = "", required = true) @RequestParam("file") MultipartFile file,
@ApiParam(name = "group", value = "groupe projet", defaultValue = "", required = true) @RequestParam("group") String group,
@ApiParam(name = "projectId", value = "id projet (francevisas, diplomatie...)", defaultValue = "", required = true) @RequestParam("projectId") String projectId,
@ApiParam(name = "version", value = "version du projet", defaultValue = "", required = true) @RequestParam("version") String version,
@ApiParam(name = "env", value = "environnement (dev, prod, formation...)", defaultValue = "", required = true) @RequestParam("env") String env) {
try {
Ressource ressource = new Ressource(file.getBytes(), group, projectId, version, env,
PropertiesFileUtils.getPropertiesFilename());
getRessourceService().save(ressource);
return ressource.getMetadata();
} catch (RuntimeException e) {
log.error("Error while uploading.", e);
throw e;
} catch (Exception e) {
log.error("Error while uploading.", e);
throw new RuntimeException(e);
}
}
答
在你DoSave就会()方法调用getServiceUrl()方法和你的路径添加到它。 getServiceUrl()必须返回一些其他域。要检查它,请在doSave()方法中进入调试模式,并查看getService方法是否为您提供了正确的值。此外,请尝试使用getServiceUrl为Postman提供的域的POST请求。
这似乎很清楚。该URL不接受POST。你有什么问题? – shmosel
@shmosel为什么我不能发布? – Mercer
我不知道春天的异常格式,但是我猜想看到'oswsPageNotFound'因为URL不正确而被重定向到“页面未找到”页面,而页面不支持'POST' – AxelH