在android网络编程里,客户端与服务器端采用json方式传递数据。服务器端是怎么接受和返回数据呢?

2025-02-25 10:37:28
推荐回答(1个)
回答1:

int formDataLength = request.getContentLength();
// 取得ServletInputStream输入流对象
DataInputStream dataStream = new DataInputStream(
request.getInputStream());
byte body[] = new byte[formDataLength];
int totalBytes = 0;
while (totalBytes < formDataLength) {
int bytes = dataStream.read(body, totalBytes, formDataLength);
totalBytes += bytes;
}
String json = new String(body, "ISO-8859-1");
System.out.println(json);