HttpCilent 字节流数据传输 博客分类: javaHttpClient HttpClientByteArrayEntity
程序员文章站
2024-03-22 19:29:34
...
public static String pustJs(int cssjs,String js){ HttpClient httpClient = new DefaultHttpClient(); String url = "http://XXX/servlet/EditCssJs?act=push&format=json"; HttpPost post = new HttpPost(url); HttpResponse response = null; String json_str = ""; try { String str="{cssjs:"+cssjs+",js:"+Tools.cite_replace(js)+"}"; ByteArrayEntity arrayEntity = new ByteArrayEntity(Tools.aes(1,str.getBytes("utf-8"),"xTe5qbuheBYD8xp7")); arrayEntity.setContentType("application/octet-stream"); post.setEntity(arrayEntity); response = httpClient.execute(post);//执行请求 HttpEntity entity = response.getEntity(); if(response.getStatusLine().getStatusCode() == 200){ if (entity != null) {//如果没有错误返回码 json_str = EntityUtils.toString(entity); } } EntityUtils.consume(entity);//关闭HttpEntity的流 } catch (Exception e){ e.printStackTrace(); } return json_str; }