title: Send data to REST service from java
body: <p>I have implemented REST service in C# to upload an image :</p>
  
  <pre><code>[OperationContract]
  [WebInvoke(Method = "PUT", UriTemplate = "add/{idAlbum}/{name}/image")]
  void Add(string idAlbum, string name, Stream image);
  </code></pre>
  
  <p>I have succeeded to use it with a C# client :</p>
  
  <pre><code>byte[] image = lireFichier(@"C:\Users\user\Pictures\asap2.jpeg");
  WebClient client = new WebClient();
  client.Headers.Add("Content-Type", "image/jpeg");
  var results = client.UploadData("http://localhost:1767/ImageService.svc/add/1/REST/image", "PUT", image);
  </code></pre>
  
  <p>So now I want to use it with a java client (android) like this (Not work) :</p>
  
  <pre><code>HttpURLConnection conn = ( HttpURLConnection ) new URL( "http://localhost:1767/ImageService.svc/add/1/RESTjava/image" ).openConnection();  
  
  conn.setRequestMethod("PUT");
  
  conn.setDoOutput( true );
  conn.connect(); 
  
  OutputStream out = conn.getOutputStream();  
  
  Bitmap img = ((BitmapDrawable)getResources().getDrawable(R.drawable.entourage)).getBitmap();
  ByteArrayOutputStream bao = new ByteArrayOutputStream();
  img.compress(Bitmap.CompressFormat.JPEG, 90, bao);
  byte[] data = bao.toByteArray();
  out.write(data);
  </code></pre>
  
  <p>I haven't any error but this didn't work. No Exceptions.</p>
  
  <pre><code> 06-05 14:11:57.736: I/ASAP PICS(746): onPreExecute
   06-05 14:11:57.745: I/ASAP PICS(746): doInBackground
   06-05 14:11:57.816: I/System.out(746): 405
   06-05 14:44:26.245: D/dalvikvm(971): GC freed 238 objects / 332400 bytes in 34ms
   06-05 14:11:57.905: I/ASAP PICS(746): onPostExecute
  </code></pre>