1

我有以下測試用例,我想發佈一塊json數據,但現在我得到了404,我在這裏做錯了什麼?WSRequest POST FunctionalTest中的JSON對象最終會得到404

@Test 
public void testIndex() { 
    User user = new User("[email protected]", "secret", "test", "(111)111-1111"); 
    Gson gson = new Gson(); 
    String postJson = gson.toJson(user); 

    // post to add the new user 
    WSRequest postRequest = WS.url("http://localhost:9001/user/add"); 
    postRequest.body = postJson; 
    HttpResponse postResponse = postRequest.post(); 
    assertEquals(postResponse.getStatus(), (Integer)200); 
} 

回答

1

一個HTTP 404方式,無論你的路徑不正確,或接收控制器POST請求的方法中,你正在嘗試做一個重定向到一個不存在的頁面。

看到你的代碼(直接檢查狀態)我敢打賭。你能在這裏添加你的路線文件的代碼嗎?並驗證Play是否在9001運行,而不是9000?