Android webserver:如何知道收到的请求方法(GET或POST)

时间:2014-03-01 07:33:15

标签: android http post get handler

在我的类DeviceHandler中,我想知道所使用的HTTP请求方法;我不明白我的HttpRequest对象怎么样?

public class DeviceHandler implements HttpRequestHandler {

...

public void handle(HttpRequest request, HttpResponse response,
                        HttpContext httpContext) throws HttpException,
                                                IOException {

// I want to dispatch the treatment according GET or POST request received from my client

谢谢你们!

安东尼

1 个答案:

答案 0 :(得分:2)

这是文档

http://developer.android.com/reference/org/apache/http/HttpRequest.html

使用

RequestLine rl = request.getRequestLine();

检索RequestLine实例,然后可以调用

String m = rl.getMethod();

获取请求方法。