嗨,我試圖做一個登錄界面,在html和發送與愛可信至@RestController和@PostMapping的用戶名和密碼,在這一刻,我得到響應的服務器,但問題是客戶端的響應,因爲當我嘗試在日誌中打印響應時,出現錯誤400。錯誤400在愛可信當我嘗試連接到Spring MVC的
愛可信:
var url = 'rest/loginParametros';
axios.post(url, {
user: this.username,
password: this.password
})
.then(function (response) {
console.log(response);
})
.catch(function (error) {
console.log(error);
});
RequestMapping
@org.springframework.web.bind.annotation.RestController
@RequestMapping("/rest")
public class RestController {
private final Log log = LogFactory.getLog(RestController.class);
@PostMapping("/loginParametros")
public ResponseEntity<Boolean> loginParametros(@RequestParam(value = "user", required = true) String user,
@RequestParam(value = "password", required = true) String password)
{
log.info("user: " + user + " password: " + password);
if(user.equals("hitzu") && password.equals("hitzu"))
return new ResponseEntity<>(true, HttpStatus.OK);
return new ResponseEntity<>(false, HttpStatus.OK);
}
}
而且,與郵遞員消耗restService當我得到的迴應
你是否檢查過你實際上是在發送用戶名和密碼?這可能是你的js變量沒有在你發佈的時候設置(this.username和this.password)。一種方法很容易檢查:只需用硬編碼的有效用戶名和密碼替換這些變量作爲測試 –