wampserver에 연결하고 버튼 (btnget)을 눌러 Android 앱에서 웹 페이지 콘텐츠를 축배하고 싶지만 버튼을 클릭 할 때 토스트가되지 않습니다. 어디에 문제가 있습니까?로컬 호스트에서 읽을 수 없습니다
public class Connect extends AsyncTask {
public String link="";
public Connect(String link){
this.link=link;
}
@Override
protected Object doInBackground(Object[] params) {
try{
URL url=new URL(link);
URLConnection connection=url.openConnection();
BufferedReader reader=new BufferedReader(new
InputStreamReader(connection.getInputStream()));
StringBuilder builder=new StringBuilder();
String line=null;
while((line=reader.readLine())!=null){
builder.append(line);
}
MainActivity.data=builder.toString();
}catch (Exception e){
}
return "";
}}
이것이 주요 활동 클래스 :
public class MainActivity extends AppCompatActivity {
public static String data="";
Button getData;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*address of the webpage on localhost:http://IP/path */
new Connect("http://192.168.56.1/localhost/shop/ss.php").execute();
getData=(Button)findViewById(R.id.btnGet);
getData.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(MainActivity.this,data, Toast.LENGTH_SHORT).show();
}});
};
}
이것은 Apache 서버 구성 방법에 따라 다릅니다. 그러나이'http : // 192.168.56.1/localhost/shop/ss.php'는 아마도'http : // 192.168.56.1/shop/ss.php'이어야합니다. – RiggsFolly
'192.168.56.1'은 ip 아파치를 실행하고 라우터의 IP 주소가 아닌 PC의 주소 ?? – RiggsFolly
아파치를 실행하는 PC의 IP 주소를 어떻게 찾을 수 있습니까? – Ayoub