JavaSpring:使用多个参数发出POST请求

JavaSpring:使用多个参数发出POST请求,java,spring,rest,http,spring-boot,Java,Spring,Rest,Http,Spring Boot,我试图在春季模拟REST调用: guess{game:'cdaeaa',guess:'e} 其结果如下: {gameId:'cdaeaa',word:'uuuuuuuuu',不正确:1,状态:'ACTIVE'} 我需要做一个函数,它有两个参数。它应该返回游戏数据。游戏类如下所示: public class Game { private final String gameId; private final String word; private String guessedWord; priv

我试图在春季模拟REST调用:
guess{game:'cdaeaa',guess:'e}
其结果如下:
{gameId:'cdaeaa',word:'uuuuuuuuu',不正确:1,状态:'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 405表示您尝试使用HTTP GET而不是HTTP POST。

您使用浏览器发出请求。默认情况下,浏览器使用GET方法


使用经过调整的工具,如curl或postman,提出发帖请求。

您需要调用
http://localhost:8080/%project-name%/guess/{asewqd}/{c}
而不是
http://localhost:8080/guess/{asewqd}/{c}
,将%project name%替换为项目名称。项目名称是什么意思?部署的应用程序名称,例如,如果项目名为game,url将为{asewqd}/{c}pom.xml中的artifactId。这不起作用。我得到一个404错误。但是我有method=RequestMethod.POST是的,你的方法只接受POST。但是,由于您可以读取错误消息中的最后一行,因此您正在请求get。要测试POST请求,您应该使用Postman()@jdickel,这就是curl的情况。curl“{vcdvnt}/{b}”{“时间戳”:“2018-04-27T12:16:49.125+0000”,“状态”:405,“错误”:“不允许使用方法”,“消息”:“不支持请求方法”“获取”,“路径”:“/guess/vcdvnt/b”}
//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;
}