Reputation: 2166
how to post nested parameters using httppost with urlencoding?for example
{
"album": {
"photos":[
{"id":"1"},
{"id":"2"},
{"id":"3"}
]
},
"name":"jhon",
"uid":"[email protected]",
"pwd":"password"
}
how to post the "album" parameters. name,uid,pwd are basic nameValuePairs.
Upvotes: 0
Views: 541
Reputation: 3826
You can go ahead and create json object and then send it as follows
JsonObject jsonObject = /** Create your json Object **/
And then use it to post to the server
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
URL url = //Your URL HERE
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setConnectTimeout(10000);
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setRequestProperty("Content-Type", "application/json");
DataOutputStream wr = new DataOutputStream(conn.getOutputStream());
wr.writeBytes(jsonObject.toString());
wr.flush();
wr.close();
conn.connect();
Upvotes: 1