0

I know there are a number of questions related to this topic but none of them has worked for me.

I have a String that contains some cookies in the form key=value; key=value; .... My app:

public class MainActivity extends AppCompatActivity {

    private WebView webView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        webView = new WebView(this);
        setContentView(webView);

        configWebView();
        loadCookies();
   }

    @SuppressLint("SetJavaScriptEnabled")
    void configWebView() {
        webView.getSettings().setJavaScriptEnabled(true);
        webView.setWebViewClient(new WebViewClient() {
            @Override
            public WebResourceResponse shouldInterceptRequest(WebView view, WebResourceRequest request) {
                 Map<String, String> requestHeaders = request.getRequestHeaders();
                 return super.shouldInterceptRequest(view, request);
            }
        });
    }

    void loadCookies() {
        // Do things
        loadPage(cookies);
    }

    void loadPage(String cookies) {
        CookieManager cookieManager = CookieManager.getInstance();

        for (String cookie : cookies.split(";")) {
            cookieManager.setCookie(DOMAIN, cookie.trim());
        }
        cookieManager.flush();

        webView.loadPage(URL);
    }
}

I don't see the result I'm expecting and if I inspect the content of requestHeaders, I see there are no Cookies passed to the server. What am I missing?

andr
  • 93
  • 2
  • 4

0 Answers0