HttpCilent 字节流数据传输

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

猜你喜欢

转载自zihai367.iteye.com/blog/2279041