title: Intercept POST requests in a WebView
body: <p>I'm developping an Android application filtering the requests (with a white list) and using a custom <code>SSLSocketFactory</code>. For this, I've developed a custom <code>WebViewClient</code> and I have overridden the <code>shouldInterceptRequest</code> method. I can filter and use my <code>SocketFactory</code> with the GET requests but I can't intercept the POST requests.</p>
  
  <p>So, is there a way to intercept the POST requests in a <code>WebView</code> ?</p>
  
  <p>Here is the code of the shouldInterceptRequest method :</p>
  
  <pre><code>public final WebResourceResponse shouldInterceptRequest(WebView view, String urlStr) {
      URI uri = URI.create(urlStr);
      String scheme = uri.getScheme();
      // If scheme not http(s), let the default webview manage it
      if(!"http".equals(scheme) &amp;&amp; !"https".equals(scheme)) {
          return null;
      }
      URL url = uri.toURL();
  
      if(doCancelRequest(url)) {
          // Empty response
          Log.d(TAG, "URL filtered: " + url);
          return new WebResourceResponse("text/plain", "UTF-8", new EmptyInputStream());
  
      } else {
          Log.d(TAG, "URL: " + url);
  
          HttpURLConnection conn = (HttpURLConnection) url.openConnection();
          conn.setRequestProperty("User-Agent", mSettings.getUserAgentString());
  
          // Configure connections
          configureConnection(conn);
  
          String mimeType = conn.getContentType();
          String encoding = conn.getContentEncoding();
  
          if(mimeType != null &amp;&amp; mimeType.contains(CONTENT_TYPE_SPLIT)) {
              String[] split = mimeType.split(CONTENT_TYPE_SPLIT);
              mimeType = split[0];
  
              Matcher matcher = CONTENT_TYPE_PATTERN.matcher(split[1]);
              if(matcher.find()) {
                  encoding = matcher.group(1);
              }
          }
  
          InputStream is = conn.getInputStream();
          return new WebResourceResponse(mimeType, encoding, is);
      }
  }
  </code></pre>