この JsonArray を HTTP リクエストとともにクライアントからサーバーに送信し、それをサーブレット ページにフェッチする必要があります。要件が異なるため、NameValuePair クラスは使用しません。
任意の助けをいただければ幸いです。
聞くのは、パラメーターを送信するために使用していたコードですが、今回はjsonArrayなので使用できません
Map<String, String> params = new HashMap<String, String>();
params.put(Constants.NAME, name);
そして、体を作ります。
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();
そしてHTTPリクエスト。
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);