I use restful between Drupal 7 and Android app. I logged in successful and got 3 variable session_id, session_name and token When I use POST method to create node. I getting error : "node type is required" This is my code :
private class addArticleTask extends AsyncTask<String, Integer, Integer> {
protected Integer doInBackground(String... params) {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://mysite/endpoint/node");
try {
//get title and body UI elements
TextView txtTitle = (TextView) findViewById(R.id.editTitle);
TextView txtBody = (TextView) findViewById(R.id.editBody);
//extract text from UI elements and remove extra spaces
JSONObject json = new JSONObject();
String title=txtTitle.getText().toString().trim();
String body=txtBody.getText().toString().trim();
//add raw json to be sent along with the HTTP POST request
StringEntity se = new StringEntity("{ \"title\" : \"Sample post\" , \"type\" : \"article\" , \"body\" : { \"und\" :[{ \"value\" : \"comments about something\" }]} }");
se.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
se.setContentType(new BasicHeader("Cookie",session_name+"="+session_id));
se.setContentType(new BasicHeader("X-CSRF-Token",token));
httppost.setEntity(se);
HttpResponse response = httpclient.execute(httppost);
Log.v("Return add article", EntityUtils.toString(response.getEntity()));
return 0;
}catch (Exception e) {
Log.v("Error adding article",e.getMessage());
}
return 0;
}
In Logcat : Return add article : ["node type is required"] any one help me.
http://mysite/endpoint/node.json