在下面的代码中,执行没有超出 HttpResponse 语句。它之前的 Toast 被显示,但不是它之后的 Toast。没有例外。谁能告诉我为什么?
我通过从图库中选择图像来获取此 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();
我也看过一些以前的问题,但没有任何效果。