title: How to send Image with HttpPost in Android
body: <p>I have to send Image to php server via HttpPost, but my code isn't working...</p>
  
  <pre><code>public void postAddToServer() {
  
      String URL="http://xyz.com.au/abc/users/webappadpost/?userid=12531&amp;listtype=2&amp;listcatid=2&amp;listsubcatid=3&amp;listtitle=testTitle&amp;listdesc=justDemo&amp;listprice=1&amp;listsuburb=adelate&amp;listphone=9895623148&amp;listavailable=1&amp;listcondtn=1&amp;listoldcondtn=3";
  
      ByteArrayOutputStream bao = new ByteArrayOutputStream();
      post_add_bitmap_image.compress(Bitmap.CompressFormat.JPEG, 90, bao);
      byte [] ba = bao.toByteArray();
      String baImage=Base64.encodeBytes(ba);
  
      try {
          String lineEnd = "\r\n";
          String twoHyphens = "--";
          String boundary = "xxxxxxxx";
          //String EndBoundary = "";
          String str = twoHyphens + boundary + lineEnd;
  
          String str4 = "Content-Disposition: form-data; name=\"image\"";
          String str5 = "Content-Type: image/jpg";
          String str6 = twoHyphens + boundary + twoHyphens;
  
          String StrTotal ="\r\n" + str + str4 + "\r\n" +"\r\n"+ baImage + "\r\n" + str6;
  
          HttpPost post = new HttpPost(URL);
          post.addHeader("Content-Type","multipart/form-data;boundary="+boundary);
          post.addHeader("Content-Type","image/jpg");
  
          StringEntity se = new StringEntity(StrTotal);
          se.setContentEncoding("UTF-8");
  
          post.setEntity(se);
  
          HttpClient client= new DefaultHttpClient();
          HttpResponse response = client.execute(post);
  
          HttpEntity getResEntity=response.getEntity();
          System.out.println("RESPONSE getResEntity : "+getResEntity.toString());
          String result="";
  
          if(getResEntity!=null){
              result=EntityUtils.toString(getResEntity);
              System.out.println("result from server: "+result);
  
              if(result!=null){
                  JSONObject object=new JSONObject(result);
                  statusFlag=object.getString("status");
                  statusFlagMessage=object.getString("message");
              }
              else{
                  System.out.println("NULL response from server.");
              }                       
          }
      }
      catch (RuntimeException e) {
  }
      catch (Exception e) {
  }
  }
  </code></pre>
  
  <p>Is the URL in the right form for Post method? Or it should be something like this... <code>URL="http://xyz.com.au/abc/users/webappadpost"</code></p>
  
  <p>Any suggestion and help will be appreciated.  </p>