java解析带斜杠的参数_Java Spring MVC应用程序仅接受带有斜杠的POST请求
war文件名是forms.war。 web.xml中的url模式為"/"
控制器操作的@RequestMapping為"/"
如果遇到localhost:8080 /表單,則RequestMethod.GET操作正常工作
如果針對(duì)localhost:8080/forms點(diǎn)擊發(fā)布數(shù)據(jù),則不會(huì)觸發(fā)RequestMethod.POST操作
POST請(qǐng)求提供302重定向
當(dāng)我點(diǎn)擊localhost:8080/forms/時(shí),POST請(qǐng)求正常工作
醇>
任何使POST請(qǐng)求工作而不尾隨斜杠的解決方案?
以下是我用來(lái)測(cè)試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請(qǐng)求但不適用于/ forms
總結(jié)
以上是生活随笔為你收集整理的java解析带斜杠的参数_Java Spring MVC应用程序仅接受带有斜杠的POST请求的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 新胜达车怎么样 全面评测新胜达车的性能和
- 下一篇: 真润康有哪些防伪标识?