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類通常應當使用而不是 這一個,因爲它支持所有相同的操作,但速度更快,因爲 它不執行同步。 –