how to get a the value of an http post as a whole?

2019-08-23 08:12发布

Is it my ideea or in rest-web services a post comes "with no name", so say something...

I mean, is the post the whole body, minus headers???

so, how can I parse such a post message with java?

do I have to use

HttpServletRequest.getInputStream?

http://www.softlab.ntua.gr/facilities/documentation/unix/java/servlet2.2/javax/servlet/http/HttpServletResponse.html

any useful example?

and how do I make such a call? I mean, posting value in the body and not in a specific parameter...

thanks a lot

2条回答
干净又极端
2楼-- · 2019-08-23 08:32

The server side code would look like the following:

StringBuilder input = new StringBuilder();
BufferedReader reader = request.getReader();
String line = reader.readLine();
while (line != null) {
    input.append(line);
    line = reader.readLine();
}

Where request is the HttpServletRequest. For testing this from the client side, you can use Poster with Firefox.

查看更多
家丑人穷心不美
3楼-- · 2019-08-23 08:38

Fiddler is really useful for this sort of thing. It is acts as a standard http proxy on your local machine. You can view the post body and headers etc in it's interface. You just have to tell your code to use an HTTP proxy (usually just 1 or 2 lines of )

查看更多
登录 后发表回答