ここからサーバーにpost idea
行きたいです。このため、私には正確なアイデアはありませんが、これまでのところ試してみました。drupal
android
タイトルと本文をフォーマットに変換しtitle
てサーバーに渡します。 または投稿してみましたbody
json
individual title and body
combine title & body
個別のタイトルと本文を追加する場合:
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("type","page"));
params.add(new BasicNameValuePair("title",title));
params.add(new BasicNameValuePair("body",jsonnode.toString()));
// jsonnode value is {"und":[{"value":"body value"}]}
System.out.println("value of the params =============> "+params);
くださいstatus code 401
I/System.out( 524): @@@@@@2 jsonnode=======>{"und":[{"value":"body value"}]}
I/System.out( 524): value of the combine node=======>{"type":"article","body":{"und":[{"value":"body value"}]},"title":"title"}
I/System.out( 524): value of the params =============> [type=page, title=title, body={"und":[{"value":"body value"}]}]
W/DefaultRequestDirector( 524): Authentication error: Unable to respond to any of these challenges: {}
I/System.out( 524): =========> statusCode post idea=====> 401
タイトルと本文を組み合わせる:
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("node",json.toString()));
// json value is {"type":"article","body":{"und":[{"value":"body"}]},"title":"title"}
System.out.println("value of the params =============> "+params);
くださいstatus code 406
I/System.out( 571): @@@@@@2 jsonnode=======>{"und":[{"value":"body"}]}
I/System.out( 571): value of the combine node=======>{"type":"article","body":{"und":[{"value":"body"}]},"title":"title"}
I/System.out( 571): value of the params =============> [node={"type":"article","body":{"und":[{"value":"body"}]},"title":"title"}]
I/System.out( 571): =========> statusCode post idea=====> 406
Httpconnection:
public static String makeWebForPostIdea(String url, String title,String body)
{
JSONStringer jsonobject = null;
JSONObject json = null;
JSONObject jsonnode = null;
DefaultHttpClient client = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
try {
JSONObject jsonvalue = new JSONObject();
jsonvalue.put("value", body.toString());
JSONArray array = new JSONArray();
array.put(jsonvalue);
jsonnode = new JSONObject();
jsonnode.put("und", array);
System.out.println("@@@@@@2 jsonnode=======>"+jsonnode.toString());
} catch (JSONException e3) {
// TODO Auto-generated catch block
e3.printStackTrace();
}
try {
//jsonobject = new JSONStringer().object().key("und").array().object().key("value").value(body).endObject().endArray().endObject();
json = new JSONObject();
json.put("title",title);
json.put("body", jsonnode);
json.put("type","article");
System.out.println("value of the combine node=======>"+json.toString());
//System.out.println("=============>"+jsonobject);
} catch (JSONException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new BasicNameValuePair("node",json.toString()));
// params.add(new BasicNameValuePair("type","page"));
//params.add(new BasicNameValuePair("title",title));
//params.add(new BasicNameValuePair("body",jsonnode.toString()));
System.out.println("value of the params =============> "+params);
UrlEncodedFormEntity formEntity = null;
try {
formEntity = new UrlEncodedFormEntity(params);
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
post.setEntity(formEntity);
try {
HttpResponse response = client.execute(post);
int statusCode = response.getStatusLine().getStatusCode();
System.out.println("=========> statusCode post idea=====> "+statusCode);
if (statusCode == HttpStatus.SC_OK)
{
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
return iStream_to_String(is);
}
else
{
return "Hello This is status ==> :"+String.valueOf(statusCode);
}
} catch (UnsupportedEncodingException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
public static String iStream_to_String(InputStream is1) {
BufferedReader rd = new BufferedReader(new InputStreamReader(is1), 4096);
String line;
StringBuilder sb = new StringBuilder();
try {
while ((line = rd.readLine()) != null) {
sb.append(line);
}
rd.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
String contentOfMyInputStream = sb.toString();
return contentOfMyInputStream;
}
}