Android WebView.postUrl() 在发布到 HTTPS URL 时显示空白屏幕
在我的 Android 应用程序中,我将数据从 WebView
发布到 https
servlet URL,如下所示。
String postData = "fileContents=" + fileCon;
WebView.postUrl(url, EncodingUtils.getBytes(postData, "BASE64"));
上面代码中的 URL 是我必须发布的 servlet URL一些数据,然后我从那里重定向到其他一些 URL。
当 servlet URL 仅为 HTTP
时,上述代码运行良好。但当更改为 HTTPS
时,它显示空白屏幕。
我尝试了以下 Android HTTPS
问题的解决方案: http://blog.antoine.li/index.html php/2010/10/android-trusting-ssl-certificates/
我从 onCreate()
方法中删除了上述代码并尝试了以下代码
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();
}
现在我可以发布数据并从那里它也正在重定向。但我仍然看到一个空白屏幕。
是因为我没有 loadUrl
或 postUrl
我看到的是空白屏幕吗?
或者我应该将上面的代码放在 WebView
的任何方法中?
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
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个
从InputStream到String的方法:
}
Try this
InputStream to String method:
}