[英]Java: how to handle/parse incoming HTTP requests?
I would like to receive parameters via plain text and http requests. 我想通过纯文本和http请求接收参数。 The data is coming in, but I'm stuck with processing it correctly.
数据正在输入,但是我一直坚持正确处理它。
Here is some pseudocode of what I would like to achieve: 这是我想要实现的一些伪代码:
// ...
String input = in.readLine();
if (HttpHelperClass.isValidHttpRequest(input)) {
// process http request
MyHttpRequest = HttpHelperClass.processInput(input);
if (MyHttpRequest.isMethod(HTTP_METHOD_GET)) {
String name = MyHttpRequest.getParameter('name');
String response = HttpHelperClass.buildResponse("Hello " + name, 200);
out.println(response);
}
} else {
// process plain text
}
Does Java have something like this out of the box or can anyone recommend anything? Java是否开箱即用,还是有人可以推荐任何东西?
Thanks in advance! 提前致谢!
Your best bet is to use UrlQuerySanitizer
. 最好的选择是使用
UrlQuerySanitizer
。 Use this to parse the URL and then call getValue("param-name")
to get the desired parameter values. 使用它来解析URL,然后调用
getValue("param-name")
以获取所需的参数值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.