欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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;
	}