In my android app, I am posting data to a https
servlet URL from a WebView
as shown below
String postData = "fileContents=" + fileCon;
WebView.postUrl(url, EncodingUtils.getBytes(postData, "BASE64"));
The URL in the above code is a servlet URL for which I have to post some data and from there I am redirecting to some other URL.
The above code worked fine when the servlet URL is just HTTP
. But when changed to HTTPS
, it is showing a blank screen.
I tried the following solution for android HTTPS
problem:
http://blog.antoine.li/index.php/2010/10/android-trusting-ssl-certificates/
I removed the above code from onCreate()
method and tried the following code
ArrayList<NameValuePair> postParameters = new ArrayList<NameValuePair>();
postParameters.add(new BasicNameValuePair("fileContents", fileCon));
DefaultHttpClient client = new MyHttpClient(getApplicationContext());
try {
HttpPost request = new HttpPost(url);
UrlEncodedFormEntity formEntity = new UrlEncodedFormEntity(postParameters);
request.setEntity(formEntity);
HttpResponse resp = client.execute(request);
} catch(Exception e){
e.printStackTrace();
}
Now I am able to post the data and from there it is redirecting also. But still I am seeing a blank screen.
Is it because I don't have either loadUrl
or a postUrl
I am seeing a blank screen?
Or should I put the above code in any method of WebView
?