HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(url).openConnection();
httpURLConnection.setConnectTimeout(10 * 1000);
httpURLConnection.setRequestMethod("GET");
int code = httpURLConnection.getResponseCode();
if (code == 200) {
InputStream inputStream = httpURLConnection.getInputStream();
byte[] bytes = new byte[1024];
int length = 0;
StringBuilder stringBuilder = new StringBuilder();
while ((length = inputStream.read(bytes)) != -1)
stringBuilder.append(bytes);
Log.v("s",strignBuilder.toString());
stringBuilder.append(bytes);
不能这么写,这么写调用的是bytes这个数组的toString()
应该是
{
String t = new String(bytes);
stringBuilder.append(bytes);
}