Android Java-将HttpPost结果转换为byte []
-
27-10-2019 - |
题
我正在尝试从服务器获取HttpPost
结果,并将其转换为字节数组,并从byte[]
获取特定字节。现在,我正在使用此代码,并且可以正常工作。我需要将其更改为我想做的。这是代码:
通用标签
由于此HttpPost,我得到了一个字符串,我需要像我一样将其转换为字节并从中获取特定的字节。像从15元素开始到25或类似的东西。有什么建议我该怎么做?
提前感谢所有建议和帮助。
解决方案
从数组中提取子数组是通过arrayCopy http://developer.android.com/reference/java/lang/System.html#arraycopy%28java.lang.Object,%20int,%20java.lang.Object,%20int,%20int%29
对于元素15到25: 通用标签
其他提示
改为使用EntityUtils.toByteArray()
方法:
通用标签
要获取数组的前5位,请使用 Arrays.copyOf()
方法:
通用标签
Use
execute(HttpUriRequest request, ResponseHandler<? extends T> responseHandler)
instead of
execute(HttpUriRequest request)
with custom responseHandler. This way you can handle input stream directly and do anything you want with it. Using EntityUtils is GC ineficient I suppose. If you care about this kind of stuff.
不隶属于 StackOverflow