无法从localhost读取

时间:2017-09-05 08:30:20

标签: wampserver connect localserver

我想连接到wampserver并通过按下按钮(btnget)在Android应用程序中烘烤网页内容但是当我点击按钮时它不会吐司。问题出在哪里? 我在localhost上的页面是“ss.php”

这是连接类:

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();
        }});
};

}

1 个答案:

答案 0 :(得分:0)

如果我没有误认为在WAMP实例上本地托管的站点的链接应该如下所示:<FontFamily x:Key="Montserrat">pack://application:,,,/xxx;Component/Fonts/#Montserrat</FontFamily> <Style x:Key="TBRoman" TargetType="{x:Type TextBlock}"> <Setter Property="FontFamily" Value="{StaticResource Montserrat}" /> </Style> (或您在wamp设置中配置的其他端口号)