Skip to content

Instantly share code, notes, and snippets.

@mancdevcarl
Last active December 18, 2015 10:19
Show Gist options
  • Save mancdevcarl/5767317 to your computer and use it in GitHub Desktop.
Save mancdevcarl/5767317 to your computer and use it in GitHub Desktop.
POST
String sourceString = "";
HttpURLConnection connection;
OutputStreamWriter request = null;
URL url = null;
String response = null;
String params = "refext=http://offliberty.com&track=" + uri[0];
try {
url = new URL("http://offliberty.com/off.php");
connection = (HttpURLConnection) url.openConnection();
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
connection.setRequestMethod("POST");
request = new OutputStreamWriter(connection.getOutputStream());
request.write(params);
request.flush();
request.close();
String line = "";
InputStreamReader isr = new InputStreamReader(
connection.getInputStream());
BufferedReader reader = new BufferedReader(isr);
StringBuilder sb = new StringBuilder();
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
// Response from server after login process will be stored in
// response variable.
response = sb.toString();
// You can perform UI operations here
Log.d("sss", response);
isr.close();
reader.close();
} catch (IOException e) {
// Error
}
return sourceString;
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.myurl.com/app/page.php");
List < NameValuePair > nameValuePairs = new ArrayList < NameValuePair > (5);
nameValuePairs.add(new BasicNameValuePair("type", "20"));
nameValuePairs.add(new BasicNameValuePair("mob", "919895865899"));
nameValuePairs.add(new BasicNameValuePair("pack", "0"));
nameValuePairs.add(new BasicNameValuePair("exchk", "1"));
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
Log.d("myapp", "works till here. 2");
try {
HttpResponse response = httpclient.execute(httppost);
Log.d("myapp", "response " + response.getEntity());
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment