我有一个web服务/ ws / forgetPassword。当我使用get访问它时,我正在
<html><head><title>VMware vFabric tc Runtime 2.9.3.RELEASE/7.0.42.A.RELEASE - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>The requested resource is not available.</u></p><HR size="1" noshade="noshade"><h3>VMware vFabric tc Runtime 2.9.3.RELEASE/7.0.42.A.RELEASE</h3></body></html>
但是当我把它转换成Post时,它工作正常,我得到了以下回复。
{
httpResponse: "200"
httpMessage: "OK"
resetPasswordUrl: "If your email is registered with us, an email will be sent to you with further instructions."
}
发布方法
@RequestMapping(value = "/forgetPassword", method = RequestMethod.POST)
public RestResponseWrapper forgotPassword(HttpServletRequest request, HttpServletResponse response) {
RestResponseWrapper responseWrapper = new RestResponseWrapper();
try {
String email = request.getParameter("email");
logger.debug("Email " + email);
UserCes userCes = getService().getUserByEmail(email);
if (userCes != null) {
String validationCode = RandomStringUtils.randomAlphabetic(40);
ForgotPassword forgotPassword = new ForgotPassword();
forgotPassword.setCreatedBy(CesUtility.getUsername());
forgotPassword.setCreatedOn(DateTimeUtility.getCurrentTime());
forgotPassword.setEmail(email);
forgotPassword.setValidationCode(validationCode);
getBaseCrudService().save(forgotPassword);
response.setStatus(HttpStatus.OK.value());
responseWrapper.setHttpResponse(HttpStatus.OK + "");
responseWrapper.setHttpMessage(HttpStatus.OK.getReasonPhrase());
responseWrapper.setResetPasswordUrl(getApplicationContext().getMessage("authauth.forgetpassword",
new Object[] { validationCode }, Locale.US));
}else{
response.setStatus(HttpStatus.NOT_FOUND.value());
responseWrapper.setHttpResponse(HttpStatus.NOT_FOUND + "");
responseWrapper.setHttpMessage(HttpStatus.NOT_FOUND.getReasonPhrase());
}
} catch (Exception e) {
responseWrapper.setHttpResponse(HttpStatus.INTERNAL_SERVER_ERROR + "");
responseWrapper.setHttpMessage(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
e.printStackTrace();
}
return responseWrapper;
}
我的获取方法
@RequestMapping(value = "/forgetPassword/{email:.+}", method = RequestMethod.GET)
public RestResponseWrapper forgotPassword(@PathVariable final String email, HttpServletRequest request, HttpServletResponse response) {
RestResponseWrapper responseWrapper = new RestResponseWrapper();
try {
logger.debug("Email " + email);
UserCes userCes = getService().getUserByEmail(email);
if (userCes != null) {
String validationCode = RandomStringUtils.randomAlphabetic(40);
ForgotPassword forgotPassword = new ForgotPassword();
forgotPassword.setCreatedBy(CesUtility.getUsername());
forgotPassword.setCreatedOn(DateTimeUtility.getCurrentTime());
forgotPassword.setEmail(email);
forgotPassword.setValidationCode(validationCode);
getBaseCrudService().save(forgotPassword);
response.setStatus(HttpStatus.OK.value());
responseWrapper.setHttpResponse(HttpStatus.OK + "");
responseWrapper.setHttpMessage(HttpStatus.OK.getReasonPhrase());
responseWrapper.setResetPasswordUrl(getApplicationContext().getMessage("authauth.forgetpassword",
new Object[] { validationCode }, Locale.US));
}else{
response.setStatus(HttpStatus.NOT_FOUND.value());
responseWrapper.setHttpResponse(HttpStatus.NOT_FOUND + "");
responseWrapper.setHttpMessage(HttpStatus.NOT_FOUND.getReasonPhrase());
}
} catch (Exception e) {
responseWrapper.setHttpResponse(HttpStatus.INTERNAL_SERVER_ERROR + "");
responseWrapper.setHttpMessage(HttpStatus.INTERNAL_SERVER_ERROR.getReasonPhrase());
response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
e.printStackTrace();
}
logger.info("response.getContentType(): " + response.getContentType());
logger.info(responseWrapper.toString());
return responseWrapper;
}
所以
期待尽快收到你的回复。
答案 0 :(得分:0)
状态代码406表示Accept
标头设置为服务器无法提供的类型。例如,如果您设置Accept: application/json
但服务器在text/plain
中发送响应,则通常会返回406错误。