title: How to send string array in url as x-www-form-urlencoded format?
body: <p>I want to send multiple values in one key, like sendTo[] -string array and values comma separated in that like abcd@gmail.com,pqrs@gmail.com.</p>
  
  <p>This I tried to achieve using string builder, appended all values using comma separated and then add the builder in hash map with the key.</p>
  
  <p>Like this : </p>
  
  <pre><code> StringBuilder emailbuilder = new StringBuilder();
                      for (String mail : mEmailList) {
  
                          emailbuilder.append(mail+",");
                          i++;
                      }
  
      data.put("send_to[]", emailbuilder.toString());
  </code></pre>
  
  <p>So it results in hashmap as abcd@gmail.com,pqrs@gmail.com,  -- string like this gets added as value for key send_to[].</p>
  
  <p>Later, the type of data sending is x-www-form-urlencoded, so I am converting data into that format.</p>
  
  <p>function to convert :</p>
  
  <pre><code> private String getDataString(HashMap&lt;String, String&gt; params) throws UnsupportedEncodingException {
      StringBuilder result = new StringBuilder();
      boolean first = true;
      for (Map.Entry&lt;String, String&gt; entry : params.entrySet()) {
          if (first)
              first = false;
          else
              result.append("&amp;");
          result.append(URLEncoder.encode(entry.getKey(), "UTF-8"));
          result.append("=");
          result.append(URLEncoder.encode(entry.getValue(), "UTF-8"));
      }
      return result.toString();
  }
  </code></pre>
  
  <p>But, after converting it converts the values too. The send_to[] key , value becomes like ---<code>&amp;send_to%5B%5D=realdammy%40hotmail.com%2Csiddhijambhale%40gmail.com%2C</code></p>
  
  <p>It converts brackets and comma into % format. I need to send data like --- send_to key and value abcd@gmail.com,pqrs@gmail.com </p>
  
  <p>How can I achieve this? Please help Thank you...</p>
  
  <p>EDIT: The function to run the request.</p>
  
  <pre><code>public String sendPostRequest(String data) {
  
      try {
  
          URL url = new URL(api);
          HttpURLConnection con = (HttpURLConnection) url.openConnection();
          con.setRequestMethod("POST");
          con.setRequestProperty("content-type", "application/x-www-form-urlencoded");
          con.setDoOutput(true);
          con.setDoInput(true);
          OutputStreamWriter writer = new OutputStreamWriter(con.getOutputStream());
  
          try {
              writer.write(data);
          } catch (Exception e) {
              Log.e("Exception111", e.toString());
          }
  
          writer.close();
  
          int responseCode = con.getResponseCode();
          if (responseCode == HttpURLConnection.HTTP_OK || responseCode == HttpURLConnection.HTTP_CREATED) {
              StringBuilder sb = new StringBuilder();
              BufferedReader reader = new BufferedReader(new InputStreamReader(con.getInputStream()));
              String line = "";
              while ((line = reader.readLine()) != null) {
                  sb.append(line);
              }
              reader.close();
              Log.d("ServerResponse", new String(sb));
              String output = new String(sb);
              return output;
          } else {
              Log.e("Exception", "" + responseCode);
          }
      }
      catch(IOException e)
      {
          Log.e("Exception", "" + e.toString());
      }
      return null;
  }
  </code></pre>