试图上传Base64编码的字符串,服务器行为不端给出404错误

My code:

 //bitmap to base64
 bitmap.compress(Bitmap.CompressFormat.PNG, 90, stream);
 byte[] byte_arr = stream.toByteArray();
 imageEncoded[y] = Base64.encodeToString(byte_arr,     Base64.DEFAULT);

 //httppost
 HttpClient client = new DefaultHttpClient();
 HttpPost httppost = new HttpPost(url);

 httppost.setEntity(new UrlEncodedFormEntity(params, "utf-8"));
 HttpResponse r =  client.execute(httppost);
 HttpEntity httpEntity = r.getEntity();

Server code is a basic print_r($_POST) to view posted data.

Server response with base64 string post: Error 404: document not found

Server response normal without base64 string post.

I can view the page (ie. http://myserver.com/script.php) with no error in browser.

edit:

test here: http://bentabols.xyz/h2.php

try to upload with/without the base64 string.. without works

driving me crayz.. pls help

edit: added params

params.add(new BasicNameValuePair("postitem", "1"));
params.add(new BasicNameValuePair("name", "Item Name"));
params.add(new BasicNameValuePair("price", "232"));
params.add(new BasicNameValuePair("section", "forsale"));
params.add(new BasicNameValuePair("warranty", "nowarranty"));
params.add(new BasicNameValuePair("condition", "used"));
params.add(new BasicNameValuePair("province", "albay"));
params.add(new BasicNameValuePair("duration", "5"));
params.add(new BasicNameValuePair("category", "computers"));
params.add(new BasicNameValuePair("description", "desc"));

for (int p = 0; p < imagepaths.length; p++) {
     params.add(new BasicNameValuePair("image_"+p, imageEncoded[p]));
     params.add(new BasicNameValuePair("imgnames_"+p, imagenames[p]));
}

You should get the real path of your image that you get it from onActivityResult

    @Override
        protected void onActivityResult(int requestCode, int resultCode, Intent data) {
            super.onActivityResult(requestCode, resultCode, data);
            If (resultCode == RESULT_OK) {
                if (requestCode == 1) {
                    Bitmap bm = (Bitmap) data.getExtras().get("data");
                    MediaStore.Images.Media.insertImage(getContentResolver(), bm, null, null);
                    Uri tempUri = getImageUri(getApplicationContext(), bm); 
                    stro = getRealPathFromURI(tempUri);

                    } else if (requestCode == 2) {

                Uri selectedImage = data.getData();
                String[] filePath = { MediaStore.Images.Media.DATA };
                Cursor c = getContentResolver().query(selectedImage, filePath,
                        null, null, null);
                c.moveToFirst();
                int columnIndex = c.getColumnIndex(filePath[0]);

                String picturePath = c.getString(columnIndex);
                c.close();
                // uploadFile(picturePath);
                stro=picturePath;
          }
    }

and add this method to get the real path of the image

public String getRealPathFromURI(Uri uri) {
        Cursor cursor = getContentResolver().query(uri, null, null, null, null); 
        cursor.moveToFirst(); 
        int idx = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA); 
        return cursor.getString(idx); 
    }

and add this code in your doInBackground

List<NameValuePair> pairs = new ArrayList<NameValuePair>();
pairs.add(new BasicNameValuePair("image", stro));
try {
                HttpClient httpClient = new DefaultHttpClient();
                HttpContext localContext = new BasicHttpContext();
                HttpPost httpPost = new HttpPost(DOMAINURL1);
                MultipartEntity entity = new MultipartEntity(
                        HttpMultipartMode.BROWSER_COMPATIBLE);

                for (int index = 0; index < pairs.size(); index++) {
                    if (pairs.get(index).getName().equalsIgnoreCase("image")) {
                        // If the key equals to "image", we use FileBody to
                        // transfer the data
                        try {
                            // File f = new File(pairs.get(index).getValue());
                            File f = new File(stro);
                            entity.addPart(pairs.get(index).getName(),new FileBody(f));

                        } catch (Exception e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    } else {
                        // Normal string data
                        entity.addPart(pairs.get(index).getName(),new StringBody(pairs.get(index).getValue()));
                    }
                }

                httpPost.setEntity(entity);
                HttpResponse response = httpClient.execute(httpPost,localContext);
                if (response != null) {
                    InputStream in = response.getEntity().getContent(); // Get
                                                                        // the
                                                                        // data
                                                                        // in
                                                                        // the
                                                                        // entity
                    InputStreamReader reader = new InputStreamReader(in);
                    BufferedReader bf1 = new BufferedReader(reader);
                    validuser = bf1.readLine();



                }
            } catch (UnsupportedEncodingException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IllegalStateException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

But I do highly recommend you not to use this way and use network library to make your API calls and I recommend you to use Retrofit. This will save to you alot of time.