I am trying to send text values to server which are name, phone, location, remarks but every time each value is missing first time name is not going , next time phone and next location...
Update:
Jsoncode:
public static String POST(String url, Persoenter code heren person){
InputStream inputStream = null;
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
String json = "";
JSONObject jsonObject = new JSONObject();
jsonObject.accumulate("name",person.getName());
jsonObject.accumulate("phone", person.getPhone());
jsonObject.accumulate("remarrks",person.getRemarks());
jsonObject.accumulate("credated_dt", person.getCreatedat());
jsonObject.accumulate("emp_code", person.getCreatedby());
jsonObject.accumulate("location", person.getLocation());
jsonObject.accumulate("add_fld1", "Test");
jsonObject.accumulate("add_fld2", "Test");
jsonObject.accumulate("add_fld3", "Test");
json = jsonObject.toString();
StringEntity se = new StringEntity(json);
Log.e("sent",""+json);
httpPost.setEntity(se);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
HttpResponse httpResponse = httpclient.execute(httpPost);
inputStream = httpResponse.getEntity().getContent();
if(inputStream != null)
result = convertInputStreamToString(inputStream);
else
result = "Did not work!";
} catch (Exception e) {
Log.d("InputStream", e.getLocalizedMessage());
}
return result;
}
Httppost
private class sync extends AsyncTask<String, String, String> {
InputStream inputStream = null;
OutputStream outputStream = null;
protected String doInBackground(String... urls) {
person = new Person();
person.setName(eName.getText().toString());
person.setPhone(ePhonenumber.getText().toString());
person.setLocation(eLocation.getText().toString());
person.setRemarks(eRemarks.getText().toString());
person.setCreatedby(eCreatedby.getText().toString());
person.setCreatedat(eCreatedat.getText().toString());
return POST(urls[0],person);
}
@Override
protected void onPreExecute() {
progress.setTitle("Connecting to server");
progress.setMessage("Sending Data.... Please wait!");
progress.setCanceledOnTouchOutside(false);
progress.show();
}
@Override
protected void onPostExecute(String s) {
progress.dismiss();
Intent Homeintent = getIntent();
Homeintent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
finish();
startActivity(Homeintent);
}
Output 1:{"name":"beta33","phone":"33","remarrks":"33","credated_dt":"2017-12-20 11:56:32","emp_code":"test@gmail.com","location":"33"} 2:{"name":"beta33","phone":"33","remarrks":"33","credated_dt":"2017-12-20 11:56:43","emp_code":"test@gmail.com","location":"33"} 3:{"name":"","phone":"34","remarrks":"34","credated_dt":"2017-12-20 11:56:52","emp_code":"test@gmail.com","location":"34"}
After trying one or two attemps now the name is not going i don't know why..please someone help me out of this