Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class RequestHandler {
- public String postRequest(String hurl, String mUsername, String mPassword)
- {
- OutputStreamWriter request;
- HttpURLConnection post_connection;
- URL url;
- String response = null;
- String parameters = "UserName="+mUsername+"&Password="+mPassword;
- try
- {
- url = new URL(hurl);
- post_connection = (HttpURLConnection) url.openConnection();
- post_connection.setDoOutput(true);
- post_connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
- post_connection.setRequestMethod("POST");
- request = new OutputStreamWriter(post_connection.getOutputStream());
- request.write(parameters);
- request.flush();
- request.close();
- String line = "";
- InputStreamReader isr = new InputStreamReader(post_connection.getInputStream());
- BufferedReader reader = new BufferedReader(isr);
- StringBuilder sb = new StringBuilder();
- while ((line = reader.readLine()) != null)
- {
- sb.append(line).append("\n");
- }
- response = sb.toString();
- Log.d(LOG_TAG, response);
- Log.d(LOG_TAG, "Code: " + post_connection.getResponseCode());
- isr.close();
- reader.close();
- }
- catch(IOException e)
- {
- Log.e(LOG_TAG, e.toString());
- }
- return response;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement