Set a cookie to a webView in Android

前端 未结 6 1681
挽巷
挽巷 2020-12-05 07:13

I\'m getting a HttpResponse from a server when checking if a username or password is correct. When I load the url in a webview I want

6条回答
  •  一个人的身影
    2020-12-05 07:54

    It's quite simple really.

    String cookieString = "cookie_name=cookie_value; path=/";
    CookieManager.getInstance().setCookie(baseUrl, cookieString);
    

    where cookieString is formatted the same as a more traditional Set-Cookie HTTP header, and baseUrl is the site the cookie should belong to.

提交回复
热议问题