AndroidStudioで(私のアプリを通して)ウェブサイトのhtmlソースを取得しようとしている場合、ページには終了メッセージと異なるコンテンツが表示され、私はウェブビューも使用していません。Android php connection
私は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を示す画像を追加しました –
私の解決策をチェックしてください、これは前に直面していました –