大家好,请问下面一段代码的功能是什么?麻烦给解释一下,谢谢!
                  URL url = new URL(httpUrl);
hConnection = (HttpURLConnection)url.openConnection();
hConnection.setRequestMethod("POST");
hConnection.connect();
int resCode = hConnection.getResponseCode();
if (resCode == 200)
{
InputStream httpInputStream = hConnection.getInputStream();
byte buf[] = new byte[1024];
for (int size = httpInputStream.read(buf); size != -1; size = httpInputStream.read(buf))
{
byte tempBuf[] = new byte[index + size];
System.arraycopy(recvBuf, 0, tempBuf, 0, index);
System.arraycopy(buf, 0, tempBuf, index, size);
recvBuf = tempBuf;
index += size;
} httpInputStream.close();
}

解决方案 »

  1.   

    请问,上面代码再加上,s = new String(recvBuf);后我要怎样才可以取出 s 的值?
      

  2.   

    URL url = new URL(httpUrl); //创建一个URL实例,参数是某个url页面的路径
    hConnection = (HttpURLConnection)url.openConnection(); //打开连接
    hConnection.setRequestMethod("POST"); //提交方式为POST
    hConnection.connect(); //开始连接
    int resCode = hConnection.getResponseCode(); //响应结果返回码
    if (resCode == 200) //成功

    InputStream httpInputStream = hConnection.getInputStream(); //返回的字符流
    byte buf[] = new byte[1024]; //创建一个字节数组,长度是1024
    for (int size = httpInputStream.read(buf); size != -1; size = httpInputStream.read(buf)) //循环读字符流

    byte tempBuf[] = new byte[index + size]; 
    System.arraycopy(recvBuf, 0, tempBuf, 0, index); 
    System.arraycopy(buf, 0, tempBuf, index, size); 
    recvBuf = tempBuf; 
    index += size; 
    } httpInputStream.close(); 
    }