Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 在android中使用HttpURLConnection时如何提取分块数据_Java_Android_Rest_Chunked Encoding - Fatal编程技术网

Java 在android中使用HttpURLConnection时如何提取分块数据

Java 在android中使用HttpURLConnection时如何提取分块数据,java,android,rest,chunked-encoding,Java,Android,Rest,Chunked Encoding,在进行RESTAPI调用时,我使用HttpURLConnection获取数据 HttpURLConnection connection = (HttpURLConnection) (new URL("http://" + account + ".table.core.windows.net/"+urlPath)).openConnection(); connection..connect(); 我得到的响应是我使用WireShark发现的分块数据。 我希望这些数据显示在我的应用程序中。如何使用

在进行RESTAPI调用时,我使用HttpURLConnection获取数据

HttpURLConnection connection = (HttpURLConnection) (new URL("http://" + account + ".table.core.windows.net/"+urlPath)).openConnection();
connection..connect();
我得到的响应是我使用WireShark发现的分块数据。 我希望这些数据显示在我的应用程序中。如何使用HttpURLConnection获取此分块数据?? 以下是wireshark的回应


嗨,下面的代码在这种情况下工作

HttpURLConnection connection = (HttpURLConnection) (new URL("http://" + account + ".table.core.windows.net/"+urlPath)).openConnection();

    signRequestSK(connection, account, key);

    connection.connect();

    ByteArrayOutputStream sink = new ByteArrayOutputStream();

    copy(connection.getInputStream(), sink, 3000);  
    byte[] downloadedFile = sink.toByteArray();
    String str = new String(downloadedFile, "UTF8");


    AlertDialog.Builder alert = new AlertDialog.Builder(this);
    alert.setTitle("Title");
    alert.setMessage(str);
    alert.show();
复制功能

      public static void copy(InputStream in, OutputStream out , int bufferSize)
           throws IOException
        {
           // Read bytes and write to destination until eof
           byte[] buf = new byte[bufferSize];
           int len = 0;
           while ((len = in.read(buf)) >= 0)
           {
              out.write(buf, 0, len);
           }
        }       
可能重复的