2014-02-16 116 views
1

我做了一些android應用程序。 要註銷,我必須發送http刪除請求到服務器。 我用loopj自由。如何發送請求http刪除使用loopj在android

所以,我這樣做。

ConnectionInfo.java

public ConnectionInfo(Context ctx) {  
    this.context = ctx;  
} 

public void sign_out(String Url, AsyncHttpResponseHandler handler) { 
    CommonClient.setCookieStore(myApplication.getCookieStore()); 
    CommonClient.delete(context, Url.toString(), handler); 
} 

public void sign_in(HashMap<String, String> params, JsonHttpResponseHandler handler) { 
    Uri.Builder requestUri = new Uri.Builder(); 
    requestUri.scheme(SCHEME); 
    requestUri.authority(HOST); 
    requestUri.path(sign_in); 
    CommonClient.post(context, requestUri.toString(), params, handler); 
} 

CommonClient.java

public class CommonClient { 
    private static final AsyncHttpClient AsyncClient = new AsyncHttpClient(); 

public static void post(Context mContext, String actionserver, 
    RequestParams params, JsonHttpResponseHandler responseHandler) { 
    AsyncClient.post(mContext, actionserver, params, responseHandler); 
} 

然後

一些Activity類,調用sign_in方法。

connectionInfo.sign_in(params, UserLoginJsonHandler); 

並且完成了一些工作,其他Activity類調用了sign_out方法。喜歡這個。

connectionInfo.sign_out(url, asyncHttpResponseHandler); 

但是,我登錄了另一個ID。 保持用戶登錄。

我覺得,不同的登錄和註銷會話或cookie的東西?

如何使用loopj註銷? 我該如何解決?

請幫幫我。

+0

對不起。我已經做了刪除的方法。 但不行。實際上,該方法工作得很好。 服務器返回204給我。 但保持登錄狀態。 – user3316557

回答

0

AsyncHttpClient上有一個delete方法,它也被重載,所以你可以選擇一個適合你需要的方法。這裏是一個樣本用法:

AsyncHttpClient client = new AsyncHttpClient(); 
AsyncClient.delete(context, url, responseHandler); 
+0

對不起。我已經做了刪除的方法。 但不行。實際上,該方法工作得很好。 服務器返回204給我。 但保持登錄狀態。 – user3316557