Java Code Examples for android.webkit.WebView#postUrl()

The following examples show how to use android.webkit.WebView#postUrl() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: WebLoadConfig.java    From HaoReader with GNU General Public License v3.0 6 votes vote down vote up
public void intoWebView(WebView webView) {
    try {
        AnalyzeUrl analyzeUrl = new AnalyzeUrl(tag, url);
        switch (analyzeUrl.getRequestMethod()) {
            case POST:
                webView.postUrl(analyzeUrl.getUrl(), analyzeUrl.getPostData());
                break;
            case GET:
                webView.loadUrl(analyzeUrl.getQueryUrl(), analyzeUrl.getHeaderMap());
                break;
            case DEFAULT:
                webView.loadUrl(analyzeUrl.getUrl(), analyzeUrl.getHeaderMap());

        }
    } catch (Exception e) {
        webView.loadUrl(url);
    }
}
 
Example 2
Source File: WawlOverrides.java    From kimai-android with MIT License 6 votes vote down vote up
public static void loadWebapp(WebView webView, AppSettings appSettings, boolean doLogin) {
    Context context = webView.getContext();
    Uri url;
    try {
        url = Uri.parse(appSettings.getProfilePathFull());
    } catch (Exception e) {
        webView.loadData(context.getString(R.string.no_valid_path), "text/html", "UTF-16");
        return;
    }

    String url_s = url.toString();
    if (appSettings.isProfileEmpty()) {
        webView.loadData(context.getString(R.string.no_valid_path), "text/html", "UTF-16");
    } else {
        webView.loadUrl(url_s);
        if (doLogin) {
            url_s += "?a=checklogin";
            String postData = "name=" + appSettings.getProfileLoginUsername() + "&password=" + appSettings.getProfileLoginPassword();
            webView.postUrl(url_s, EncodingUtils.getBytes(postData, "base64"));
        }
    }
}
 
Example 3
Source File: AjaxWebView.java    From HaoReader with GNU General Public License v3.0 5 votes vote down vote up
@SuppressLint({"SetJavaScriptEnabled", "JavascriptInterface"})
private static WebView createAjaxWebView(AjaxParams params, Handler handler) {
    WebView webView = new WebView(params.context.getApplicationContext());
    WebSettings settings = webView.getSettings();
    settings.setJavaScriptEnabled(true);
    settings.setDomStorageEnabled(true);
    settings.setBlockNetworkImage(true);
    settings .setMediaPlaybackRequiresUserGesture(false);
    settings.setUserAgentString(params.getUserAgent());
    settings.setMixedContentMode(WebSettings.MIXED_CONTENT_ALWAYS_ALLOW);
    if (params.isSniff()) {
        webView.setWebViewClient(new SnifferWebClient(params, handler));
    } else {
        webView.setWebViewClient(new HtmlWebViewClient(handler));
        webView.addJavascriptInterface(new JavaInjectMethod(handler), "OUTHTML");
    }
    switch (params.getRequestMethod()) {
        case POST:
            webView.postUrl(params.url, params.postData);
            break;
        case GET:
        case DEFAULT:
            webView.loadUrl(params.url, params.headerMap);
            break;
    }
    return webView;
}
 
Example 4
Source File: Web3WebviewManager.java    From react-native-web3-webview with MIT License 4 votes vote down vote up
@ReactProp(name = "source")
public void setSource(WebView view, @NonNull ReadableMap source) {
    if (source != null) {
        if (source.hasKey("html")) {
            String html = source.getString("html");
            if (source.hasKey("baseUrl")) {
                view.loadDataWithBaseURL(
                        source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
            } else {
                view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
            }
            return;
        }
        if (source.hasKey("uri")) {
            String url = source.getString("uri");
            String previousUrl = view.getUrl();
            if (source.hasKey("method")) {
                String method = source.getString("method");
                if (method.equals(HTTP_METHOD_POST)) {
                    byte[] postData = null;
                    if (source.hasKey("body")) {
                        String body = source.getString("body");
                        try {
                            postData = body.getBytes("UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            postData = body.getBytes();
                        }
                    }
                    if (postData == null) {
                        postData = new byte[0];
                    }
                    view.postUrl(url, postData);
                    return;
                }
            }
            HashMap<String, String> headerMap = new HashMap<>();
            if (source.hasKey("headers")) {
                ReadableMap headers = source.getMap("headers");
                ReadableMapKeySetIterator iter = headers.keySetIterator();
                while (iter.hasNextKey()) {
                    String key = iter.nextKey();
                    if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
                        if (view.getSettings() != null) {
                            view.getSettings().setUserAgentString(headers.getString(key));
                        }
                    } else {
                        headerMap.put(key, headers.getString(key));
                    }
                }
            }
            view.loadUrl(url, headerMap);
            return;
        }
    }
    view.loadUrl(BLANK_URL);
}
 
Example 5
Source File: ReactWebViewManager.java    From react-native-GPay with MIT License 4 votes vote down vote up
@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
  if (source != null) {
    if (source.hasKey("html")) {
      String html = source.getString("html");
      if (source.hasKey("baseUrl")) {
        view.loadDataWithBaseURL(
          source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
      } else {
        view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
      }
      return;
    }
    if (source.hasKey("uri")) {
      String url = source.getString("uri");
      String previousUrl = view.getUrl();
      if (previousUrl != null && previousUrl.equals(url)) {
        return;
      }
      if (source.hasKey("method")) {
        String method = source.getString("method");
        if (method.equals(HTTP_METHOD_POST)) {
          byte[] postData = null;
          if (source.hasKey("body")) {
            String body = source.getString("body");
            try {
              postData = body.getBytes("UTF-8");
            } catch (UnsupportedEncodingException e) {
              postData = body.getBytes();
            }
          }
          if (postData == null) {
            postData = new byte[0];
          }
          view.postUrl(url, postData);
          return;
        }
      }
      HashMap<String, String> headerMap = new HashMap<>();
      if (source.hasKey("headers")) {
        ReadableMap headers = source.getMap("headers");
        ReadableMapKeySetIterator iter = headers.keySetIterator();
        while (iter.hasNextKey()) {
          String key = iter.nextKey();
          if ("user-agent".equals(key.toLowerCase(Locale.ENGLISH))) {
            if (view.getSettings() != null) {
              view.getSettings().setUserAgentString(headers.getString(key));
            }
          } else {
            headerMap.put(key, headers.getString(key));
          }
        }
      }
      view.loadUrl(url, headerMap);
      return;
    }
  }
  view.loadUrl(BLANK_URL);
}
 
Example 6
Source File: MagnetWebViewManager.java    From magnet-client with Mozilla Public License 2.0 4 votes vote down vote up
@ReactProp(name = "source")
public void setSource(WebView view, @Nullable ReadableMap source) {
    if (source != null) {
        if (source.hasKey("html")) {
            String html = source.getString("html");

            if (source.hasKey("baseUrl")) {
                view.loadDataWithBaseURL(
                        source.getString("baseUrl"), html, HTML_MIME_TYPE, HTML_ENCODING, null);
            } else {
                view.loadData(html, HTML_MIME_TYPE, HTML_ENCODING);
            }

            return;
        }

        if (source.hasKey("uri")) {
            String url = source.getString("uri");

            if (source.hasKey("method")) {
                String method = source.getString("method");
                if (method.equals(HTTP_METHOD_POST)) {
                    byte[] postData = null;
                    if (source.hasKey("body")) {
                        String body = source.getString("body");
                        try {
                            postData = body.getBytes("UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            postData = body.getBytes();
                        }
                    }
                    if (postData == null) {
                        postData = new byte[0];
                    }
                    view.postUrl(url, postData);
                    return;
                }
            }

            HashMap<String, String> headerMap = new HashMap<>();
            if (source.hasKey("headers")) {
                ReadableMap headers = source.getMap("headers");
                ReadableMapKeySetIterator iter = headers.keySetIterator();
                while (iter.hasNextKey()) {
                    String key = iter.nextKey();
                    headerMap.put(key, headers.getString(key));
                }
            }
            view.loadUrl(url, headerMap);
            return;
        }
    }

    view.loadUrl(BLANK_URL);
}