无法以json格式将图像字节数组编码字符串发送到服务器

I am sending image from device in byte array from activity by getting image from gallery and converted it to byte array and encoded string later.

Uri selectedImageUri = data.getData();
                    selectedImagePath = getPath(selectedImageUri);
                    System.out.println("Image Path : " + selectedImagePath);

                    //Log.d("gallery ---- > ", "" + data.getExtras().get("data"));

                    imageView.setImageURI(selectedImageUri);
                    imageView.setMaxHeight(200);
                    imageView.setMaxWidth(200);

                    imageView.setDrawingCacheEnabled(true);


                    BitmapFactory.Options options0 = new BitmapFactory.Options();
                    options0.inSampleSize = 2;
                    // options.inJustDecodeBounds = true;
                    options0.inScaled = false;
                    options0.inDither = false;
                    options0.inPreferredConfig = Bitmap.Config.ARGB_8888;

                    bmp = BitmapFactory.decodeFile(selectedImagePath);

                    ByteArrayOutputStream baos0 = new ByteArrayOutputStream();


                    bmp.compress(Bitmap.CompressFormat.JPEG, 100, baos0);
                    byte[] imageBytes0 = baos0.toByteArray();




                    Log.e("Byte Array:", imageBytes0.toString());

                    String encodedImage =Base64.encodeToString(imageBytes0,Base64.URL_SAFE);
  • But, When I pass this string through URL to send to server(ASP.NET), it is giving exception in HTTP Connection as,

JSONParser Class

public class JSONParser {

    static InputStream is = null;
    static JSONObject jObj = null;
    static String json = "";

    // constructor
    public JSONParser() {


    }

    public JSONArray getJSONfromURL(String url) {
        InputStream is = null;
        String result = "";
        JSONArray jArray = null;

        try {
            HttpClient httpclient = new DefaultHttpClient();
            HttpPost httpget = new HttpPost(url);
            HttpResponse response = httpclient.execute(httpget);
            //  response = 
            HttpEntity entity = response.getEntity();
            is = entity.getContent(); 

            if(is!=null) {

                BufferedReader reader = new BufferedReader(new InputStreamReader(is,"iso-8859-1"),8);
                StringBuilder sb = new StringBuilder();
                String line = null;
                while ((line = reader.readLine()) != null) {
                    sb.append(line + "
");
                }

                is.close();
                result=sb.toString();
            }
            jArray = new JSONArray(result);    
        } catch (ClientProtocolException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return jArray;
    }

}
  • Exception is coming in these line,

HttpPost httpget = new HttpPost(url); HttpResponse response = httpclient.execute(httpget);

Logcat trace

java.lang.IllegalArgumentException: Illegal character in query at index 161

Image byte array encoded string much bigger in URL and may be because of this connection is not made.

Please suggest me to solve this issue..

Thanks in advance