i have to send This JsonArray With HTTP Request from client to sever and have to fetch it on to servlet page..without NameValuePair Class because my requirement is diffrent.
any help would be appreciated.
hear is some code i was using to send parameters but this time its jsonArray so i cant use it
Map<String, String> params = new HashMap<String, String>();
params.put(Constants.NAME, name);
and then building the body.
StringBuilder bodyBuilder = new StringBuilder();
Iterator<Entry<String, String>> iterator = params.entrySet().iterator();
// constructs the POST body using the parameters
while (iterator.hasNext()) {
Entry<String, String> param = iterator.next();
bodyBuilder.append(param.getKey()).append('=')
.append(param.getValue());
if (iterator.hasNext()) {
bodyBuilder.append('&');
}
}
String body = bodyBuilder.toString();
and then HTTP Request.
conn = (HttpURLConnection)url.openConnection();
conn.setDoOutput(true);
conn.setUseCaches(false);
conn.setFixedLengthStreamingMode(bytes.length);
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type",
"application/x-www-forurlencoded;charset=UTF-8");
// post the request
OutputStream out = conn.getOutputStream();
out.write(bytes);