【发布时间】:2011-10-04 10:54:58
【问题描述】:
在我的 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.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的任何方法中?
【问题讨论】:
标签: android https httpclient android-webview