I am building an android application where user enter the name, email ID This are parse to URL and all the user data are store there.
Now, When an user send this info an ID is generated at that Time on server and it resend to me that unique ID as the URL response.
How can I get this response and store it. So I can use it For my future use.
Here is my code for parsing this value to that URL -
private class DownloadJSON extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Create a progressdialog
}
@Override
protected String doInBackground(String... params) {
// Create an array
//public String postData() {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://URL/api/user");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>2);
nameValuePairs.add(new BasicNameValuePair("name", name));
nameValuePairs.add(new BasicNameValuePair("email", email));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream parse = entity.getContent();
return getStringFromInputStream(parse);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
return "No Result !";
}
//convert InputStream to String
private String getStringFromInputStream(InputStream is) {
BufferedReader br = null;
StringBuilder sb = new StringBuilder();
String line;
try {
br = new BufferedReader(new InputStreamReader(is));
while ((line = br.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (br != null) {
try {
br.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return sb.toString();
}
@Override
protected void onPostExecute(String args) {
}
}
I am new to android please help me!!