Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法以json格式向服务器发送图像字节数组编码字符串_Java_Php_Android_Arrays_Json - Fatal编程技术网

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

Java 无法以json格式向服务器发送图像字节数组编码字符串,java,php,android,arrays,json,Java,Php,Android,Arrays,Json,我通过从gallery中获取图像并在稍后将其转换为字节数组和编码字符串,从activity中以字节数组的形式从设备发送图像 Uri selectedImageUri = data.getData(); selectedImagePath = getPath(selectedImageUri); System.out.println("Image Path : " + selectedImagePath);

我通过从gallery中获取图像并在稍后将其转换为字节数组和编码字符串,从activity中以字节数组的形式从设备发送图像

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);
  • 但是,当我通过URL将此字符串发送到服务器(ASP.NET)时,它在HTTP连接中给出了异常,如下所示:
JSONParser类

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 + "\n");
                }

                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;
    }

}
  • 例外情况在这一行出现
HttpPost httpget=新的HttpPost(url); HttpResponse response=httpclient.execute(httpget)

Logcat跟踪

java.lang.IllegalArgumentException:索引161处查询中的非法字符

图像字节数组编码的字符串在URL中大得多,可能是因为未建立此连接

请建议我解决这个问题

提前谢谢