title: Posting image to wcf rest service from Android
body: <p>I'm having a problem to post a image to my wcf rest service. I'm posting some parameters of which one of them is a base64 utf-8 encoded string (the image).</p>
  <p>My problem is that every time I post I get &quot;bad request&quot;. Here is the code</p>
  <pre><code>public String PostImage(Drawable img) throws Exception 
  {
      HttpPost httpost = new HttpPost(&quot;http://10.0.2.2:1374/uploaditem&quot;);
      JSONStringer json = JSONStringer()
          .object()
          .key(&quot;ipm&quot;)
              .object()
                  .key(&quot;name&quot;).value(&quot;test&quot;)
                  .key(&quot;description&quot;).value(&quot;asfa&quot;)
                  .key(&quot;categoryid&quot;).value(1)
                  .key(&quot;data&quot;).value(ConvertImgToBase64Str(img))
                  .key(&quot;imagetype&quot;).value(2)
                  .key(&quot;tags&quot;).value(&quot;test;test&quot;)
              .endObject()
           .endObject();
  
      StringEntity entity = new StringEntity(json.toString());
      entity.setContentType(&quot;application/json;charset=UTF-8&quot;);//text/plain;charset=UTF-8                  
      entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE,&quot;application/json;charset=UTF-8&quot;));
      httpost.setEntity(entity); 
      return ExcecutePostRequest(httpclient,httpost);
  }
  
  //Method to convert the image to base64encoded string
  private String ConvertImgToBase64Str(Drawable img) {
      Bitmap bitmap = ((BitmapDrawable)img).getBitmap();
      ByteArrayOutputStream stream = new ByteArrayOutputStream();
      bitmap.compress(Bitmap.CompressFormat.PNG, 100, stream);
      byte[] bitmapdata = stream.toByteArray();
      return Base64.encodeToString(bitmapdata, Base64.URL_SAFE);
  }
  </code></pre>
  <p>It is something with the encoded string, but what?</p>