我曾经在服务器上读取页面,然后通过android应用程序将其转换为字符串,没有任何问题。但是由于我安装了SSL证书并重写了http://-> https://,因此无法再正常读取该页面。相反,这是从页面返回的内容:
<!DOCTYPE html><html style="height:100%"><head><title> 302 Found</title></head><body style="color: #444; margin:0;font: normal 14px/20px Arial, Helvetica, sans-serif; height:100%; background-color: #fff;"><div style="height:auto; min-height:100%; "> <div style="text-align: center; width:800px; margin-left: -400px; position:absolute; top: 30%; left:50%;"> <h1 style="margin:0; font-size:150px; line-height:150px; font-weight:bold;">302</h1><h2 style="margin-top:20px;font-size: 30px;">Found</h2><p>The document has been temporarily moved.</p></div></div><div style="color:#f0f0f0; font-size:12px;margin:auto;padding:0px 30px 0px 30px;position:relative;clear:both;height:100px;margin-top:-101px;background-color:#474747;border-top: 1px solid rgba(0,0,0,0.15);box-shadow: 0 1px 0 rgba(255, 255, 255, 0.3) inset;"><br>Proudly powered by <a style="color:#fff;" href="http://www.litespeedtech.com/error-page">LiteSpeed Web Server</a><p>Please be advised that LiteSpeed Technologies Inc. is not a web hosting company and, as such, has no control over content found on this site.</p></div></body></html>
这是我用来阅读页面的代码:
public class readtextfile extends AsyncTask<String, String, String> {
ProgressDialog progressDialog;
@Override
protected String doInBackground(String... params) {
StringBuilder response = new StringBuilder();
try {
URL url = new URL(
"http://mywebsite.com/thatpage");
BufferedReader in = new BufferedReader(new InputStreamReader(
url.openStream()));
String line = null;
while ((line = in.readLine()) != null) {
// get lines
response.append(line);
}
in.close();
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return response.toString();
}
protected void onProgressUpdate() {
// called when the background task makes any progress
}
protected void onPreExecute() {
progressDialog = new ProgressDialog(LatePaymentDamageActivity.this);
progressDialog.setMessage("wait . . .");
progressDialog.show();
}
@Override
protected void onPostExecute(String result) {
// TODO Auto-generated method stub
//process the json
}
}
我正在寻找一种更改Java代码的方法来避免该问题,而无需更改我网站的重写结构。