Android WebView.postrl()在发布到HTTPS URL时显示空白屏幕

Android WebView.postrl()在发布到HTTPS URL时显示空白屏幕,android,https,httpclient,android-webview,Android,Https,Httpclient,Android Webview,在我的android应用程序中,我从WebView向httpsservlet URL发布数据,如下所示 String postData = "fileContents=" + fileCon; WebView.postUrl(url, EncodingUtils.getBytes(postData, "BASE64")); 上面代码中的URL是一个servlet URL,我必须为其发布一些数据,并从那里重定向到其他URL 当servlet URL仅为HTTP时,上述代码运行良好。但当更改为HT

在我的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
问题尝试了以下解决方案:

我从
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();
}
ArrayList后参数=新的ArrayList();
添加(新的BasicNameValuePair(“fileContents”,fileCon));
DefaultHttpClient=newMyHttpClient(getApplicationContext());
试试{
HttpPost请求=新的HttpPost(url);
UrlEncodedFormEntity formEntity=新的UrlEncodedFormEntity(后参数);
请求。setEntity(formEntity);
HttpResponse resp=client.execute(请求);
}捕获(例外e){
e、 printStackTrace();
}
现在,我可以发布数据,并从那里它是重定向也。但我仍然看到一个空白屏幕

是不是因为我既没有
loadUrl
也没有
postUrl
我看到了一个空白屏幕

或者我应该将上述代码放在
WebView
的任何方法中吗?

试试这个

    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);

    //Get data
     HttpEntity entity = resp.getEntity();
     InputStream is = entity.getContent();
     String data = convertStreamToString(is);
     browser=(WebView)findViewById(R.id.myWebView);
     browser.loadData(data,"text/html", "UTF-8");
} catch(Exception e){
    e.printStackTrace();
}
}

试试这个
private static String convertStreamToString(InputStream is) {

BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();

String line = null;
try {
    while ((line = reader.readLine()) != null) {
        sb.append((line + "\n"));
    }
} catch (IOException e) {
    e.printStackTrace();
} finally {
    try {
        is.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
return sb.toString();