title: Converting curl request to android HttpURLConnection Post Request
body: <p>Hi iam developing an android app in which i used mailchimp service.In short
  I have no knowledge of curl and i want to convert the following curl request to httpurlconnection post request.
  Any help would appreciated and thanks in advanced.Here is the curl code</p>
  
  <pre><code>curl --request POST \
  --url 'https://usX.api.mailchimp.com/3.0/lists/57afe96172/members' \
  --user 'anystring:apikey' \
  --header 'content-type: application/json' \
  --data '{"email_address":"urist.mcvankab+3@freddiesjokes.com", "status":"subscribed"}' \
  --include
  </code></pre>
  
  <blockquote>
    <p>i coded it and below is my android code but in the logcat i get 400
    Bad Request</p>
  </blockquote>
  
  <pre><code>try {
                  urlConnection = (HttpURLConnection) params[0].openConnection();
                  urlConnection.setUseCaches(false);
                  urlConnection.setDoOutput(true);
                  urlConnection.setDoInput(true);
                  urlConnection.setRequestMethod("POST");
                  urlConnection.setRequestProperty("Authorization",basicAuth);
                  urlConnection.setRequestProperty("Content-Type","application/json");
                  JSONObject info= new JSONObject();
                  info.put("email_address",email);
                  info.put("status","subscribed");
  
                  OutputStreamWriter wr = new OutputStreamWriter(urlConnection.getOutputStream());
                  wr.write(info.toString());
                  wr.flush();
                  wr.close();
                  StringBuilder sb=new StringBuilder();
                  int HttpResult =urlConnection.getResponseCode();
                  if(HttpResult ==HttpURLConnection.HTTP_OK){
                      BufferedReader br = new BufferedReader(new InputStreamReader(
                              urlConnection.getInputStream(),"utf-8"));
                      String line = null;
                      while ((line = br.readLine()) != null) {
                          sb.append(line + "\n");
                      }
                      br.close();
  
                      System.out.println("  "+sb.toString());
  
                  }else{
                      System.out.println(urlConnection.getResponseMessage());
                  }
                  Log.e("authkey==&gt; ",apiKey+"");
                  //  InputStream in = new BufferedInputStream(urlConnection.getInputStream());
              }catch (JSONException e){
                  e.printStackTrace();
              }
              catch (IOException e) {
                  e.printStackTrace();
                  Log.d("URL","Error in URL Connection");
              } finally {
                  urlConnection.disconnect();
                  Log.d("URL","Error in URL Connection,Connection Closed");
              }
  </code></pre>