javascript - 从mysql下载数据到Android时出错

标签 javascript php android mysql

从 mysql 下载数据到 android 时出现与 javascript 相关的错误 ...当我显示下载的字符串时,它显示了一个我包含在图像中的 html 页面...请帮助我尽快摆脱它。

下载的字符串“sb”在这里被制作为Toa​​st,它显示如下:

Downloaded String "sb" is made as Toast here and it shows like this

代码:

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/

相关文章:

javascript - 替换javascript中的字符

javascript - ng 级 : Assign a single class to multiple expression

javascript - 理解 ES6 中的循环依赖

javascript - 将数据从 html 表单发送到 php 脚本并将结果返回到 ajax/js/jquery

php - 如何使用get方法滚动到页面的位置?

android - Gradle 在 Bintray 的 Maven 仓库中找不到 .aar 文件

谷歌地图中每个标记的Android不同信息窗口

javascript - 使用 "checked"属性时是否正确的 XHTML 语法?

php - 如何在 PHP 5.x 上安装 http_pecl?

java - 向某个pc应用的所有android客户端发送消息