【发布时间】:2017-07-27 19:22:22
【问题描述】:
如果我尝试使用 AndroidStudio(通过我的应用程序)获取网站的 html 源代码,页面会显示不同的内容以及结束消息,而我没有使用网络视图或类似的东西。
我在 hostweb 中有一个 php 文件,我想在 textview 中显示消息:
<?php
echo "hello from the other side";
?>
我的安卓代码是:
public class MainActivity extends AppCompatActivity {
TextView text;
FloatingActionButton fab;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fab = (FloatingActionButton) findViewById(R.id.fab);
text = (TextView) findViewById(R.id.text);
try
{
String myurl = "http://keeplearning.eb2a.com/hello.php";
new MyAsyncTaskgetNews().execute(myurl);
}catch (Exception ex){}
}
private class MyAsyncTaskgetNews extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... params) {
String NewsData="";
try
{
URL url = new URL(params[0]);
HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
InputStream in = new BufferedInputStream(urlConnection.getInputStream());
NewsData=Stream2String(in);
in.close();
publishProgress(NewsData );
} catch (Exception e) {
}
return null;
}
@Override
protected void onProgressUpdate(String... values) {
try {
text.setText(values[0]);
}catch (Exception ex){
ex.printStackTrace();
}
}
}
public String Stream2String(InputStream inputStream) {
BufferedReader bureader=new BufferedReader( new InputStreamReader(inputStream));
String line ;
String Text="";
try{
while((line=bureader.readLine())!=null) {
Text+=line;
}
inputStream.close();
}catch (Exception ex){}
return Text;
}
}
当我运行它时,我得到了这个错误
在浏览器中激活 JavaScript。 enter image description here
知道我应该怎么做吗?或者我启用javascript?
【问题讨论】:
-
这个错误到底是哪里来的?可以分享一下logcat吗?
-
我添加了一张显示错误的图片@JoeyPinto
-
检查我的解决方案,我以前遇到过这种情况
-
是的,谢谢先生
标签: javascript php android web-hosting