使用http客户端android studio在base64中上传图像

时间:2018-05-06 16:34:12

标签: php android mysql http android-studio

我在这个函数中有一个问题,这个代码在后台运行,上传摄像头拍摄的图像并转换为基数46,我有一些错误。 看这个图像: android studio error

 protected String doInBackground(Void... params) {

        ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("base64", ba1));
        nameValuePairs.add(new BasicNameValuePair("ImageName", System.currentTimeMillis() + ".jpg"));
        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httppost = new HttpPost(URL);
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
            HttpResponse response = httpclient.execute(httppost);
            String st = EntityUtils.toString(response.getEntity());
            Log.v("log_tag", "In the try Loop" + st);

        } catch (Exception e) {
            Log.v("log_tag", "Error in http connection " + e.toString());
        }
        return "Success";

    }

请帮帮我 对不起语法

1 个答案:

答案 0 :(得分:0)

您可以通过在gradle中包含库来解决问题

useLibrary 'org.apache.http.legacy'