title: cURL using httppost in android java
body: <p>I'm trying to get a cURL request work in android using the httpclient. </p>
  
  <pre><code>curl -k -X POST \
  -F 'image=@00001_1.png;type=image/png' \
  -F 'svgz=@00001_1.png;type=image/svg+xml' \
  -F 'json={ 
      "text" : "Hello world!",
      "tid" : "0010",
      "timestamp" : "1342683312", 
      "location" : [ 22793, -553.3344],
      "facebook" :
      {
          "id": "4444444",
          "access_token": "7FUinHfxsCTrx",
          "expiration_date": "1358204400"                
      }
  };type=application/json' \
  https://example.com/api/posts
  </code></pre>
  
  <p>This is the code that's giving me a BAD REQUEST ERROR (400) from SERVER. </p>
  
  <pre><code>public static void example() {
          HttpClient client = getNewHttpClient();
          HttpPost httpost = new HttpPost("https://example.com/api/posts");
          httpost.addHeader("image", "@00001_1.png; type=image/png");
          httpost.addHeader("svgz", "@00001_1.png; type=image/svg+xml");
          httpost.addHeader("type", "multipart/form-data");
  //        httpost.setHeader("Content-type", "multipart/form-data");
          JSONObject data = new JSONObject();
          JSONObject facebook = new JSONObject();
          JSONArray location = new JSONArray();
          HttpResponse response = null;
          try {
              data.put("text","Hello world!");
              data.put("templateid","0010");
              data.put("timestamp","2012-07-08 09:00:45.312195368+00:00");
  
              location.put(37.7793);
              location.put(-122.4192);
              data.put("location", location);
              facebook.put("id", "4444444");
              facebook.put("access_token", "7FUinHfxsCTrx");
              facebook.put("expiration_date", "1358204400");
              data.put("facebook", facebook);
  
              System.out.println(" ---- data ----- "+data);
  
              StringEntity stringEntity = new StringEntity(data.toString(), "utf-8");
              httpost.setEntity(stringEntity);
              try {
                  response = client.execute(httpost);
                  System.out.println(" --- response --- "+response.getStatusLine().getStatusCode());
                  HttpEntity entity = response.getEntity();
                  // If the response does not enclose an entity, there is no need
                  // to worry about connection release
                  if(entity != null) {
                      // A Simple Response Read
                      InputStream instream = entity.getContent();
                      String result = convertStreamToString(instream);
                      System.out.println(" ---- result ---- "+result);
  
                      // Closing the input stream will trigger connection release
                      instream.close();
                  }
              } catch (ClientProtocolException e) {
                  e.printStackTrace();
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
          } catch (JSONException e) {
              e.printStackTrace();
          } catch (UnsupportedEncodingException e) {
              e.printStackTrace();
          }
      }
  </code></pre>
  
  <p>It works perfect from the command line, don't where I'm going wrong. Any help highly appreciated.</p>
  
  <p>Also let me know if I can do it without using any library written in C (Libcurl, etc).</p>
  
  <p>Thanks.</p>