Last active
December 18, 2015 10:19
-
-
Save mancdevcarl/5767317 to your computer and use it in GitHub Desktop.
POST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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