android
[j android] WebView posturl 사용하기
simpleyj
2022. 4. 7. 17:04
728x90
반응형
webview url과 달리 posturl 사용법을 알아보자.
1. posturl 에 넘길 데이터 값 변환 class
public class GetByte {
static byte[] myGetBytes(final String data, final String charset) {
if (data == null) {
throw new IllegalArgumentException("data may not be null");
}
if (charset == null || charset.length() == 0) {
throw new IllegalArgumentException("charset may not be null or empty");
}
try {
return data.getBytes(charset);
} catch (UnsupportedEncodingException e) {
return data.getBytes();
}
}
}
2. webview에 posturl 사용
val url = "http://www.url.com"
val data = "data=data&data2=data2"
binding.webView.postUrl(url,GetByte.myGetBytes(data, "BASE64")!!)
728x90
반응형