-3

I have my android application. I have no idea how to establish communication between the server and the application. I have a login page in the application. I want to send username and password to the server and return yes for valid input and no for invalid input.

Please tell me how to code at server as I have a public ubuntu server but I don't know what to do there in order to establish communication.

Also, what to write at the application code to send data to the server. What will be the URL of the request I have no idea. Like I have a public server IP 21.4.3.5 with username : ABC and password : XYZ . Now what will be the URL to send request to the server through the application and to receive the response?

nerdy_me
  • 451
  • 1
  • 5
  • 7

1 Answers1

2

Try this way

URL url = new URL("http://example.sitedemo.service.php");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
Uri.Builder builder = new Uri.Builder().appendQueryParameter("username", "maven")
                                       .appendQueryParameter("password", "123");
String query = builder.build().getEncodedQuery();

OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8"));
writer.write(query);
writer.flush();
writer.close();
os.close();

conn.connect();

InputStream in = new BufferedInputStream(conn.getInputStream());
response = IOUtils.toString(in, "UTF-8");
Maveňツ
  • 1
  • 12
  • 50
  • 89
  • Like you have passed the URL in URL constructor. I have IP address as my server 103.27.9.3 address but where should I put the connection python code on server and which complete URL will be given to the client for login request. I can access only terminal of server using ssh. – nerdy_me Jun 23 '15 at 11:08
  • I have googled but cant figure out one thing. I am using Django integrated with Apache 2. How can I send requests to the public server rom the android application. Like, what will be the URL to hit the server for the requests. Please give some direction. Thank you. – nerdy_me Jun 28 '15 at 13:11
  • I am getting permission denied error on integrating apache with Django. I am checked all permissions also. but still unable to find the solution. – nerdy_me Jul 15 '15 at 10:07