本文整理匯總了Java中android.webkit.WebView.postUrl方法的典型用法代碼示例。如果您正苦於以下問題:Java WebView.postUrl方法的具體用法?Java WebView.postUrl怎麽用?Java WebView.postUrl使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.webkit.WebView
的用法示例。
在下文中一共展示了WebView.postUrl方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: initWebView
import android.webkit.WebView; //導入方法依賴的package包/類
private void initWebView() {
StringBuilder data = new StringBuilder();
data.append("imei").append("=").append(DevicesUtils.getIMEI(this)).append("&");
data.append("brand").append("=").append(DevicesUtils.getBrand()).append("&");
String[] abis = DevicesUtils.getAbis();
StringBuilder builder = new StringBuilder("[");
for (String abi : abis) {
builder.append("\"").append(abi).append("\"").append(",");
}
builder.deleteCharAt(builder.length() - 1);
builder.append("]");
data.append("abis").append("=").append(builder);
final WebView webView = new WebView(this);
webView.postUrl("http://www.wrbug.com", data.toString().getBytes());
}
示例2: setSource
import android.webkit.WebView; //導入方法依賴的package包/類
@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);
}