android webview post data

호출 순서

1. javascript 에서 post 할 데이터를 plugin 으로 보낸다.

{ "username":"홍길동" , "userpassword":"" }

2. 이 데이터를 안드로이드 플러그인에서 string 으로 만든 후 , Json Object 로 보낸다.

String postData = "username="+ URLEncoder.encode(username, "UTF-8");
String params = Base64.encodeToString(params.getBytes(), Base64.URL_SAFE);

3.WebView 호출하는데서는 2번에서 암호화 한 값을 풀어서, byte[] 로 보낸다.

String tmp = new String(Base64.decode(params, Base64.URL_SAFE));

String url = "http://www.example.com";
String postData = "username=my_username&password=my_password";
webview.postUrl(url,EncodingUtils.getBytes(postData, "BASE64"));

위와 같이 보낸다.




댓글