我有一个带有以下详细信息的spring MVC应用程序
"/"
"/"
localhost:8080/forms
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
答案 0 :(得分:0)
将@RequestMapping
更改为无映射(因此不要将值设为"/"
)或"/*"
。