I want to send data from android app to remote server. I have tried to send data as a sample to the server but it is working. I am uploading my code below. I am not sure but may be my data sending formate is wrong.
The link need to show a success message. Unfortunately it not showing any change.
public void postData() throws JSONException {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://192.168.1.145/tracker/index.php/json/add_task");
JSONObject json = new JSONObject();
try {
// JSON data:
json.put("task_title", "Fahmi Rahman");
json.put("task_details", "sysdev");
JSONArray postjson=new JSONArray();
postjson.put(json);
// Post the data:
httppost.setHeader("json",json.toString());
httppost.getParams().setParameter("jsonpost",postjson);
// Execute HTTP Post Request
System.out.print(json);
HttpResponse response = httpclient.execute(httppost);
// for JSON:
if(response != null)
{
InputStream is = response.getEntity().getContent();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
//text = sb.toString();
}
//tv.setText(text);
}catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
And I need to send data this formate
{"task":{
"task_title":"All json formate",
"task_details":"View All task list, View task list by user id, Add new task"}}