Hello! There is a PHP script, there is a link to it. It receives 2 values ​​for input: username and password, which in the application are taken from the input fields (I took them). The problem is this: you need to create a post request to this script, putting the username and password parameters there. Thank you in advance!

Closed due to the fact that the essence of the question is incomprehensible to the participants dirkgntly , Streletz , D-side , pavel , Vartlok Aug 30 '16 at 12:59 .

Try to write more detailed questions. To get an answer, explain what exactly you see the problem, how to reproduce it, what you want to get as a result, etc. Give an example that clearly demonstrates the problem. If the question can be reformulated according to the rules set out in the certificate , edit it .

    1 answer 1

    In AndroidManifest.xml before the application tag, add the line:

     <uses-permission android:name="android.permission.INTERNET" /> 

    Actually, the code:

     public class PostRequest extends AsyncTask<String, Void, String> { @Override protected String doInBackground(String... strings) { String address = strings[0]; String username = strings[1]; String password = strings[2]; try { URL obj = new URL(address); HttpURLConnection con = (HttpURLConnection) obj.openConnection(); con.setRequestMethod("POST"); con.setRequestProperty("Accept-Language", "en-US,en;q=0.5"); String urlParameters = "username=" + username + "&password=" + password; con.setDoOutput(true); DataOutputStream wr = new DataOutputStream(con.getOutputStream()); wr.writeBytes(urlParameters); wr.flush(); wr.close(); BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream())); String inputLine; StringBuffer response = new StringBuffer(); while ((inputLine = in.readLine()) != null) { response.append(inputLine); } in.close(); return response.toString(); } catch (Exception e) { // catch exceptions } return null; } } 

    Runs like this:

     String responce = new PostRequest().execute("http://www.example.com/script.php", "username", "password").get(); 
    • And how can I install not English but Russian? con.setRequestProperty ("Accept-Language", "ru-RU, ru; q = 0.5"); - So? - Egor
    • @ Egor, What language? - s8am 6:39 pm