-1
我需要你的帮助来理解这件事。 我必须做一个http post请求anche我必须发送参数和一个非常巨大的json数组(data = [jsonarray])。 现在,如果我只发送参数没有问题..但我不知道我怎么也发送jsonarray。 我如何实现一个部分发送我的jsonarray? 在此先感谢。 这里是我的代码:通过HTTP发送params和Json POST
public static String post(String requestURL, HashMap<String, String> postDataParams, JSONArray jsonArray) {
URL url;
String response = "";
try {
url = new URL(requestURL);
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setReadTimeout(TIMEOUT_CONNECTION);
conn.setConnectTimeout(TIMEOUT_CONNECTION);
conn.setRequestMethod("POST");
conn.setDoInput(true);
conn.setDoOutput(true);
if (postDataParams != null) {
OutputStream os = conn.getOutputStream();
BufferedWriter writer = new BufferedWriter(
new OutputStreamWriter(os, "UTF-8"));
writer.write(getPostDataString(postDataParams));
writer.flush();
writer.close();
os.close();
}
int responseCode = conn.getResponseCode();
if (responseCode == HttpsURLConnection.HTTP_OK) {
String line;
BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream()));
while ((line = br.readLine()) != null) {
response += line;
}
} else {
response = "";
}
} catch (Exception e) {
e.printStackTrace();
response = "";
String strParams = postDataParams != null ? postDataParams.toString() : "";
IMLog.e(TAG, "Error....");
}
return response;
}
好吧,但如果JSONArray是非常巨大的?约3600件。我可以作为正常的散列表参数发送吗? – BoraBora
是的。我不认为这应该是一个问题。 –
感谢队友,有时我在一杯水中失去了我的自我! :) – BoraBora