2014-03-01 36 views
0

在我的DeviceHandler類中,我想知道使用的HTTP請求方法;我不明白如何與我的HttpRequest對象?Android webserver:如何知道收到的請求方法(GET或POST)

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 

謝謝你們!

安東尼

回答

2

這裏是文檔

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

使用

RequestLine RL = request.getRequestLine();

檢索RequestLine實例,則可以調用

串m = rl.getMethod();

得到請求方法。

+0

謝謝達里奧!你知道我如何檢索我的方法無效處理(...)中收到的數據(在POST請求的情況下)?從我的客戶端發佈JSON數據,我想在這裏找回。 – Anthony

+0

可能請求是HttpEntityEnclosingRequest的實例。因此,請使用實例來檢查它並進行轉換,然後可以調用.getEntity()來獲取HttpEntity。然後使用String json = EntityUtils.toString(entity); – Dario

相關問題