android 获取图片验证码

public void getURLimage(String url) {
    //获取图片验证码的 方法

    OkHttpClient okHttpClient = new OkHttpClient();
    Request request = new Request.Builder().url(url).build();
    Call call = okHttpClient.newCall(request);
    call.enqueue(new Callback() {
        @Override
        public void onFailure(Call call, IOException e) {
        }

        @Override
        public void onResponse(Call call, Response response) throws IOException {
            Headers headers = response.headers();
            Set<String> names = headers.names();
            for (String name:names){
               // if("Set-Cookie".equals(name)){
                 //   JSESSIONID=headers.get(name);
          //      }
            }

            InputStream is = response.body().byteStream(); //获取 字节输入流
            final Bitmap bitmap = BitmapFactory.decodeStream(is); // 把获取到的 数据 转换成 Bitmap 类型的
            getActivity().runOnUiThread(new Runnable() {
                @Override
                public void run() {
                   // Image_yanzhengma.setImageBitmap(bitmap);

                }
            });
        }
    });
}

猜你喜欢

转载自blog.csdn.net/weixin_41449643/article/details/79495445