1
在下面的代码中,执行没有超越HttpResponse语句。在显示Toast之前,不会显示它之后的内容。没有任何异常。可以告诉我为什么?HttpResponse无法正常工作
我从图库中选取一张图像即可获得该Uri,甚至可以在ImageView中显示。因此Uri没有问题。
Uri selectedImage = data.getData();
bitmap = MediaStore.Images.Media.getBitmap(getContentResolver(), selectedImage);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bitmap.compress(CompressFormat.JPEG, 100, baos);
byte ar[] = baos.toByteArray();
String s = Base64.encodeBytes(ar);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("My URL");
ArrayList<NameValuePair> list = new ArrayList<NameValuePair>();
list.add(new BasicNameValuePair("image", s));
HttpEntity entity = new UrlEncodedFormEntity(list);
httppost.setEntity(entity);
Toast.makeText(this, "Upload",Toast.LENGTH_LONG).show();
HttpResponse response = httpclient.execute(httppost); // HERE
Toast.makeText(this, "Uploaded or not?", Toast.LENGTH_LONG).show();
java.io.InputStream is = response.getEntity().getContent();
BufferedReader br = new BufferedReader(new InputStreamReader(is));
String result = br.readLine();
我曾经见过一些以前的问题,但没有工作。
你看到例外logcat的?你是否在单独的线程中运行此代码,因为网络操作不允许在Android版本> 3.x – httpdispatch 2013-05-01 10:06:39
我在2.3.6版本上运行它,Logcat中没有任何内容 – 2013-05-01 10:29:43