[英]Java Spring MVC application accepts POST requests only with trailing slash
我有一個帶有以下詳細信息的spring MVC應用程序
"/"
"/"
localhost:8080/forms
匹配,則不會觸發RequestMethod.POST操作 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
將@RequestMapping
更改為無映射(因此,甚至都不要輸入任何值,甚至"/"
)或"/*"
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.