I am trying to write data on MySQL which is on my laplop. Below code works on Emulator but code does not work on real device. I have Wifi and I have connected android device through USP for testing purpose. Please help.
@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;
}
Error message is java.io.FileNotFoundException: http://192.168.0.101/kiranapp/register.php on line
InputStream IS = httpURLConnection.getInputStream();