2

We have send a POST request to android web view , but the web view did some url decode automatically and the server side get a wrong data.

Eg: we have a signature value like aedTH5634+hjsGT78-67ty when we POST this value through webview , webview automatically convert + value to space.SO in the server signature value is wrong.How I Avoid this decode.

IOS webview workig fine it send exact value what we have POST.How we avoid this decoding from the android webview.

Help is highly appreciable,

Thanks,

vks
  • 6,649
  • 7
  • 36
  • 55

3 Answers3

4

not sure how it will help others with a similar situation but i will still give my $0.02, I was able to solve my issue like this, I used the following methods and ensured that the encoding is retained for encoding value use base64 and convert the data to base 64, read more about this here

void loadData (String data, String mimeType, String encoding)

convert data to base64 like this

String base64Data = android.util.Base64.encodeToString(yourdata.getBytes("UTF-8"), android.util.Base64.DEFAULT);

and finally put everything together like this

webView.loadData(base64Data, "text/html; charset=utf-8", "base64");
Aniruddha K.M
  • 7,361
  • 3
  • 43
  • 52
0

Maybe an Android WebView Bug? Just a workaround:

webView.loadUrl(URLEncoder.encode(yourStr));
roNn23
  • 1,532
  • 1
  • 15
  • 32
0

code works.

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT){
    this.evaluateJavascript(javascriptCommand, null);
} else {
    this.loadUrl(javascriptCommand); 
}
patrick.elmquist
  • 2,113
  • 2
  • 21
  • 35