[英]Java Spring: Make POST Request with Multiple parameters
我正在尝试在Spring中对REST调用进行建模: guess {game: 'cdaeaa', guess: 'e' }
,它输出以下内容: {gameId: 'cdaeaa', word: '____', incorrect: 1, status: 'ACTIVE'}
我基本上需要制作一个包含两个参数的函数。 它应该返回游戏数据。 游戏类如下:
public class Game {
private final String gameId;
private final String word;
private String guessedWord;
private Set<Character> guessedChars;
private GameStatus status;
private int incorrectGuesses;
private static final int MAX_TRIES = 7;}
但是,当我这样打一个电话时: http://localhost:8080/guess/{asewqd}/{c}
(是否将这些内容放在大括号中都没有关系。)我得到以下内容错误:
//POST
//make guess
@RequestMapping(value = "/guess/{game}/{guess}", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public Game makeGuess(@PathVariable String game, @PathVariable String guess, HttpSession session) throws GameDoesNotExistException, InvalidCharacterException{
Game g = getGame(game,session);
String gameId = g.getId();
if(gameId.equals(game) && guess.length() > 0) {
boolean correct = compareWords(guess, g);
if(!correct){
g.incIncorrect_guesses();
}
g.setStatus();
}
else{
if(!gameId.equals(game)) {
throw new GameDoesNotExistException(game);
}
else{
throw new InvalidCharacterException(guess);
}
}
g = getGame(game,session);
return g;
}
HTTP 405表示您尝试使用HTTP GET而不是HTTP POST。
您使用浏览器发出请求。 浏览器默认使用GET方法。
使用类似curl或postman的工具发出POST请求。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.