war文件名是forms.war。 web.xml中的url模式為"/"
控制器操作的@RequestMapping為"/"
如果遇到localhost:8080 /表單,則RequestMethod.GET操作正常工作
如果針對localhost:8080/forms點擊發布數據,則不會觸發RequestMethod.POST操作
POST請求提供302重定向
當我點擊localhost:8080/forms/時,POST請求正常工作
醇>
任何使POST請求工作而不尾隨斜杠的解決方案?
以下是我用來測試POST api的代碼:
public class HttpPostExample {
public static void main(String[] args) {
HttpClient httpClient = HttpClientBuilder.create().build();
try {
HttpPost request = new HttpPost("http://localhost:8080/forms");
StringEntity params =new StringEntity("{\"form_url\":\"admin\",\"website\":\"US_WEBSITE\",\"email\":\"testelascrip1@gmail.com\",\"cis_name\":\"testscrip1\"} ");
request.addHeader("content-type", "application/x-www-form-urlencoded");
request.setEntity(params);
HttpResponse response = httpClient.execute(request);
System.out.println("Printing the response code " + response.getStatusLine().getStatusCode());
} catch (IOException e) {
e.printStackTrace();
}
}
}
將URL更改為/ forms /適用于POST請求但不適用于/ forms