1
我使用StringBuffer
发送和接收来自Web服务的变量。return StringBuffer array
我的代码是:
// Create connection url = new URL(urlSCS + "/login"); connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Type",
"application/x-www-form-urlencoded");
connection.setRequestProperty("Content-Length",
"" + Integer.toString(urlParameters.getBytes().length));
connection.setRequestProperty("Content-Language", "pl-PL");
connection.setUseCaches(false);
connection.setDoInput(true);
connection.setDoOutput(true);
// Send request
DataOutputStream wr = new DataOutputStream(
connection.getOutputStream());
wr.writeBytes(urlParameters);
wr.flush();
wr.close();
// Get Response
InputStream is = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(is));
String line;
StringBuffer response = new StringBuffer();
while ((line = rd.readLine()) != null) {
response.append(line);
response.append('\r');
}
rd.close();
我怎样才能改变这个代码能够接收数组,而不是字符串?
我从Web服务获得的请求是这样的:{"var", "var"}
。
什么数组? '炭[]'? – adarshr
你可能想看看[这里] [1]。让我知道它是否有帮助。 [1]:http://stackoverflow.com/questions/285712/java-reading-a-file-into-an-array – MacLuq
从Javadoc中的StringBuffer'的 StringBuilder类通常应当使用而不是 这一个,因为它支持所有相同的操作,但速度更快,因为 它不执行同步。 –