直接读取文件流的方式

直接读取文件流的方式

 HttpClient httpClient = new DefaultHttpClient();
        String reqStr = new JSONUtil<String, ReasonsForDissatisfactionReqBean>().ObjectToJsonStr(commonRequestBean);
        String paramImg = URLEncoder.encode(ContentAesQos.getParamImg(reqStr));
        String url = CommonQos.NOSATISFACTION_IMG_QUERY+"?reqParam="+paramImg;
        System.out.println("url:"+url);
        //第二步:生成使用POST方法的请求对象
        HttpGet httpPost = new HttpGet(url);
        httpPost.addHeader("Content-Type", "application/json");
//        String reqStr = new JSONUtil<String, ReasonsForDissatisfactionReqBean>().ObjectToJsonStr(commonRequestBean);
//        String paramImg = ContentAesQos.getParamImg(reqStr);
//        httpPost.setEntity(new StringEntity(paramImg));
        //执行请求对象
        try {
            //第三步:执行请求对象,获取服务器发还的相应对象
            HttpResponse response = httpClient.execute(httpPost);
            //第四步:检查相应的状态是否正常:检查状态码的值是200表示正常
            Log.e("HTTP", response.getStatusLine().getStatusCode() + "");
            if (response.getStatusLine().getStatusCode() == 200) {
                //第五步:从相应对象当中取出数据,放到entity当中
                filePath = Environment.getExternalStorageDirectory()
                        .getAbsolutePath() + "/" + "qos_temp.png"; // 文件路径
                File file = new File(filePath);
                FileOutputStream outputStream = new FileOutputStream(file);
                InputStream inputStream = response.getEntity()
                        .getContent();
                byte b[] = new byte[1024];
                int j = 0;
                while ((j = inputStream.read(b)) != -1) {
                    outputStream.write(b, 0, j);
                }
                outputStream.flush();
                outputStream.close();

//                setImgView(img);
                handler.sendEmptyMessage(2);

get post 都可以

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 最开始,我对保险行业也是无比抵触。一听到是推销保险,无一例外,我立马就挂掉电话。没想到后来经历的一切,不仅让...
    李赛月阅读 7,414评论 0 0
  • 说到可转债第一说一下买入策略。 第一步,筛选出低于100元的可转债。 第二步,买入低于纯债价值的可转债。 第三...
    昌旭幽情阅读 657评论 1 1