MySQL:Android真实设备无法在PC中神秘地连接。 Emmulator能够连接

时间:2015-08-03 06:03:11

标签: php android mysql

我正在尝试在我的laplop上写MySQL的数据。 下面的代码适用于模拟器,但代码不适用于真实设备。 我有Wifi,我通过USP连接Android设备进行测试。 请帮忙。

@Override
protected String doInBackground(String... params)
{
    String reg_url = "http://192.168.0.101/kiranapp/register.php";
    String method = params[0];
    if(method.equals("register"))
    {
        String name = params[1];
        String username = params[2];
        String userpass = params[3];
        try {
            URL url = new URL(reg_url);
            HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
            httpURLConnection.setRequestMethod("POST");
            httpURLConnection.setDoOutput(true);
            OutputStream OS = httpURLConnection.getOutputStream();
            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(OS,"UTF-8"));
            String data = URLEncoder.encode("user","UTF-8") +"="+URLEncoder.encode(name,"UTF-8")+"&"+
             URLEncoder.encode("user_name","UTF-8") +"="+URLEncoder.encode(username,"UTF-8")+"&"+
             URLEncoder.encode("user_pass","UTF-8") +"="+URLEncoder.encode(userpass,"UTF-8");

            bufferedWriter.write(data);
            bufferedWriter.flush();
            bufferedWriter.close();
            OS.close();

           InputStream IS = httpURLConnection.getInputStream();
           IS.close();

            return "Registeration Successfull.........";

        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    return null;
}

错误讯息是 java.io.FileNotFoundException:http://192.168.0.101/kiranapp/register.php 在线

InputStream IS = httpURLConnection.getInputStream();

0 个答案:

没有答案