从 mysql 下载数据到 android 时出现与 javascript 相关的错误 ...当我显示下载的字符串时,它显示了一个我包含在图像中的 html 页面...请帮助我尽快摆脱它。
下载的字符串“sb”在这里被制作为Toast,它显示如下:
代码:
public class Download extends AsyncTask<Void,Integer,String>{
Context c;
String address;
ProgressDialog pd;
public Download(Context c,String address){
this.c=c;
this.address=address;
}
@Override
protected void onPostExecute(String s) {
super.onPostExecute(s);
pd.dismiss();
if(s!=null){
Toast.makeText(c,s,Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(c,"download failed",Toast.LENGTH_SHORT).show();
}
}
@Override
protected void onPreExecute() {
super.onPreExecute();
pd=new ProgressDialog(c);
pd.setTitle("Download");
pd.setMessage("Fetching Data...");
pd.show();
}
@Override
protected String doInBackground(Void... params) {
String data=downloaddata();
return data;
}
public String downloaddata() {
InputStream is=null;
String line=null;
try {
URL url = new URL(address);
HttpURLConnection con=(HttpURLConnection) url.openConnection();
is=con.getInputStream();
BufferedReader br=new BufferedReader(new InputStreamReader(is));
StringBuffer sb=new StringBuffer();
if(br!=null){
while ((line=br.readLine())!=null) {
sb.append(line+"\n");
}
br.close();is.close();con.disconnect();
}
else{
return null;
}
return sb.toString();
}
catch (MalformedURLException e){
e.printStackTrace();
}
catch (IOException e){
e.printStackTrace();
}
finally {
if(is!=null){
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return null;
}
}
最佳答案
这不是错误与Web scraping相关的东西 欲了解更多信息,请查看此thread
关于javascript - 从mysql下载数据到Android时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43487941/