public byte[] post(String url,byte[] bytes) throws Exception { HttpPost httpPost = new HttpPost(url); httpPost.setEntity(new ByteArrayEntity(bytes)); httpPost.setHeader("Content-type", "application/octet-stream;charset=UTF-8"); //这里是设置虚拟IP String remoteIp = (int) (Math.random() * 255 + 1)+"."+(int) (Math.random() * 255 + 1)+"."+(int) (Math.random() * 255 + 1)+"."+(int) (Math.random() * 255 + 1); httpPost.setHeader("X-Forwarded-For",remoteIp); CloseableHttpResponse httpResponse = HttpClients.createDefault().execute(httpPost); try { HttpEntity entityResponse = httpResponse.getEntity(); int responseCode = httpResponse.getStatusLine().getStatusCode(); int contentLength = (int) entityResponse.getContentLength(); // OutputStream out = new By
使用httpPost发送 字节流请求 byte[]
最新推荐文章于 2024-08-08 09:12:41 发布
本文详细介绍了如何使用HTTPPost方法发送字节流请求,包括准备工作、构建请求体、设置请求头和执行请求的过程。通过实例代码解析,帮助读者理解如何将byte[]数据转换为HTTP请求发送,并讨论了可能遇到的问题及解决方案。
摘要由CSDN通过智能技术生成