您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

Android将Base64字符串发布到PHP

Android将Base64字符串发布到PHP

这是图像的代码

ByteArrayOutputStream bao = new ByteArrayOutputStream();

bitmap.compress(Bitmap.CompressFormat.JPEG, 90, bao);
byte [] ba = bao.toByteArray();
String ba1=Base64.encodeBytes(ba);
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("image",ba1));

这是用于将图像发送到服务器的HTTP代码

HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://servername.com/uploadimage.PHP");
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));        
HttpResponse response = httpclient.execute(httppost);
httpentity entity = response.getEntity();
is = entity.getContent();

如果您发现更多困难,请询问我或进行检查:

PHP文件中的更改:

header('Content-Type: image/jpg; charset=utf-8');
$base=$_REQUEST['image'];
php 2022/1/1 18:19:34 有535人围观

撰写回答


你尚未登录,登录后可以

和开发者交流问题的细节

关注并接收问题和回答的更新提醒

参与内容的编辑和改进,让解决方法与时俱进

请先登录

推荐问题


联系我
置顶