从android客户端将图像发布到本地服务器

从android客户端将图像发布到本地服务器,android,Android,正在尝试确定::服务器运行正常,android未向服务器发送图像 MainActivity.java public void postImageData() throws IOException { Drawable myDrawable = getResources().getDrawable(R.drawable.image); Bitmap bitmap = ((BitmapDrawable)myDrawable).getBitmap();

正在尝试确定::服务器运行正常,android未向服务器发送图像

MainActivity.java

    public void postImageData() throws IOException
    {
        Drawable myDrawable = getResources().getDrawable(R.drawable.image);
        Bitmap bitmap = ((BitmapDrawable)myDrawable).getBitmap();
        HttpClient httpClient = new DefaultHttpClient();
        HttpPost postRequest = new HttpPost("http://127.0.0.1/Details/");
        MultipartEntity reqEntity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE);

        try{
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            bitmap.compress(CompressFormat.JPEG, 75, bos);
            byte[] data = bos.toByteArray();
            ByteArrayBody bab = new ByteArrayBody(data, "forest.jpg");
            reqEntity.addPart("key", bab);
        }
        catch(Exception e){
            //Log.v("Exception in Image", ""+e);
            reqEntity.addPart("key", new StringBody(""));
        }
        postRequest.setEntity(reqEntity);       
        HttpResponse response = httpClient.execute(postRequest);
        BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));
        String sResponse;
        StringBuilder s = new StringBuilder();
        while ((sResponse = reader.readLine()) != null) {
            s = s.append(sResponse);
        }
    }

解决此问题有什么帮助吗

谢谢

“捕获(例外e){ //Log.v(“图像中的异常”,“e”); reqEntity.addPart(“键”,新的StringBody(“”); }"? 我建议你打印stackTrace。。关联的try块中可能发生异常