title: How to send multiple JSON objects through a URLConnection?
body: <p>I'm new to Android. In this method, I'm willing to send a BEAccident object along with some Strings, but the server throws an error.</p>
  
  <p>public String SendAccident(BEAccident accident, String username,
              String password) {</p>
  
  <pre><code>    JSONObject jsonAccident = new JSONObject();
      try {
          jsonAccident.put("HasDocuments", accident.getHasDocuments());
          jsonAccident.put("ChassisNumber", accident.getChassisNumber());
          jsonAccident.put("ContainerNumber", accident.getContainerNumber());
          jsonAccident.put("Description", accident.getDescription());
          jsonAccident.put("IdTMUser", accident.getIdTMUser());
          jsonAccident.put("LicensePlate", accident.getLicensePlate());
          jsonAccident.put("LocalDateTime", accident.getLocalDateTime());
      } catch (JSONException e1) {
          return e1.getMessage();
      }
  
      try{
          // Set Request parameter
          data +="&amp;" + URLEncoder.encode("Username", "UTF-8") + "="+username;
          data +="&amp;" + URLEncoder.encode("Password", "UTF-8") + "="+password;
          data +="&amp;" + URLEncoder.encode("LoadNumber", "UTF-8") + "="+"LN0003";
          data +="&amp;" + URLEncoder.encode("Accident", "UTF-8") + "="+URLEncoder.encode(jsonAccident.toString(), "UTF-8");
  
      } catch (UnsupportedEncodingException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      } 
      BufferedReader reader = null;
      // Send data
      try {
  
          URL url = new URL(URL_SEND_ACCIDENT);
          URLConnection conn = url.openConnection();
          conn.setDoOutput(true);
          OutputStreamWriter wr = new OutputStreamWriter(
                  conn.getOutputStream());
  
          wr.write(data);
          wr.flush();
  
          // Get the server response
  
          reader = new BufferedReader(new InputStreamReader(
                  conn.getInputStream()));
          StringBuilder sb = new StringBuilder();
          String line = null;
  
          // Read Server Response
          while ((line = reader.readLine()) != null) {
              // Append server response in string
              sb.append(line + "");
          }
  
          // Append Server Response To Content String
          Content = sb.toString();
          return Content;
      } catch (Exception ex) {
          Error = ex.getMessage();
          return Error;
      } finally {
          try {
  
              reader.close();
          }
  
          catch (Exception ex) {
          }
      }
  }
  </code></pre>
  
  <p>Please advise if this is the right way to send a non-native object using URLConnection. I appreciate any response.</p>