Search in sources :

Example 1 with CookieStore

use of com.lzy.okgo.cookie.store.CookieStore in project okhttp-OkGo by jeasonlzy.

the class CookieActivity method removeCookie.

@OnClick(R.id.removeCookie)
public void removeCookie(View view) {
    HttpUrl httpUrl = HttpUrl.parse(Urls.URL_METHOD);
    CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
    cookieStore.removeCookie(httpUrl);
    showToast("详细移除cookie的代码,请看demo的代码");
}
Also used : CookieStore(com.lzy.okgo.cookie.store.CookieStore) HttpUrl(okhttp3.HttpUrl) OnClick(butterknife.OnClick)

Example 2 with CookieStore

use of com.lzy.okgo.cookie.store.CookieStore in project okhttp-OkGo by jeasonlzy.

the class CookieActivity method getAllCookie.

@OnClick(R.id.getAllCookie)
public void getAllCookie(View view) {
    //一般手动取出cookie的目的只是交给 webview 等等,非必要情况不要自己操作
    CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
    List<Cookie> allCookie = cookieStore.getAllCookie();
    showToast("所有cookie如下:" + allCookie.toString());
}
Also used : Cookie(okhttp3.Cookie) CookieStore(com.lzy.okgo.cookie.store.CookieStore) OnClick(butterknife.OnClick)

Example 3 with CookieStore

use of com.lzy.okgo.cookie.store.CookieStore in project okhttp-OkGo by jeasonlzy.

the class CookieActivity method getCookie.

@OnClick(R.id.getCookie)
public void getCookie(View view) {
    //一般手动取出cookie的目的只是交给 webview 等等,非必要情况不要自己操作
    CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
    HttpUrl httpUrl = HttpUrl.parse(Urls.URL_METHOD);
    List<Cookie> cookies = cookieStore.getCookie(httpUrl);
    showToast(httpUrl.host() + "对应的cookie如下:" + cookies.toString());
}
Also used : Cookie(okhttp3.Cookie) CookieStore(com.lzy.okgo.cookie.store.CookieStore) HttpUrl(okhttp3.HttpUrl) OnClick(butterknife.OnClick)

Example 4 with CookieStore

use of com.lzy.okgo.cookie.store.CookieStore in project okhttp-OkGo by jeasonlzy.

the class CookieActivity method addCookie.

@OnClick(R.id.addCookie)
public void addCookie(View view) {
    HttpUrl httpUrl = HttpUrl.parse(Urls.URL_METHOD);
    Cookie.Builder builder = new Cookie.Builder();
    Cookie cookie = builder.name("myCookieKey1").value("myCookieValue1").domain(httpUrl.host()).build();
    CookieStore cookieStore = OkGo.getInstance().getCookieJar().getCookieStore();
    cookieStore.saveCookie(httpUrl, cookie);
    showToast("详细添加cookie的代码,请看demo的代码");
    //
    OkGo.post(Urls.URL_TEXT_UPLOAD).tag(//
    this).execute(new StringDialogCallback(this) {

        @Override
        public void onSuccess(String s, Call call, Response response) {
            handleResponse(s, call, response);
        }

        @Override
        public void onError(Call call, Response response, Exception e) {
            super.onError(call, response, e);
            handleError(call, response);
        }
    });
}
Also used : Cookie(okhttp3.Cookie) StringDialogCallback(com.lzy.demo.callback.StringDialogCallback) Response(okhttp3.Response) CookieStore(com.lzy.okgo.cookie.store.CookieStore) Call(okhttp3.Call) HttpUrl(okhttp3.HttpUrl) OnClick(butterknife.OnClick)

Aggregations

OnClick (butterknife.OnClick)4 CookieStore (com.lzy.okgo.cookie.store.CookieStore)4 Cookie (okhttp3.Cookie)3 HttpUrl (okhttp3.HttpUrl)3 StringDialogCallback (com.lzy.demo.callback.StringDialogCallback)1 Call (okhttp3.Call)1 Response (okhttp3.Response)1