title: i need to make a java.net url fetch with a json request. Please tell me how can i call that using java in google appengine
body: <p>This is my HTTP URL</p>
  
  <pre><code>POST HTTPS://www.googleapis.com/admin/directory/v1/group
  MY json request 
  {
     "email": "sales_group@example.com",
     "name": "Sales Group",
     "description": "This is the Sales group."
  }
  </code></pre>
  
  <p>I am using Directory API to create groups.</p>
  
  <p>I never used URL fetch so far so i am not familiar with that. 
  Please help me how can i do that..</p>
  
  <p>THIS IS MY ANSWER I POSTED AFTER 2 HOURS. stackoverflow did not allow me to to answer my own question before 8 hours since i have less than 10 reputation, so forgive me for long question.
  I tried this..
      i was struggling a bit in passing json as parameter. here is my code</p>
  
  <pre><code>import java.io.IOException;
  
  import java.io.OutputStreamWriter;
  import java.net.HttpURLConnection;
  import java.net.URL;
  import java.util.logging.Logger;
  
  import javax.servlet.http.*;
  
  import com.google.appengine.labs.repackaged.org.json.JSONException;
  import com.google.appengine.labs.repackaged.org.json.JSONObject;
  
  @SuppressWarnings("serial")
  public class DirectoryApiExampleServlet extends HttpServlet {
          static Logger log = gger.getLogger(DirectoryApiExampleServlet.class.getName());
  public void doGet(HttpServletRequest req, HttpServletResponse resp)
          throws IOException {
       URL url = new URL("https://www.googleapis.com/admin/directory/v1/groups");
       HttpURLConnection connection = (HttpURLConnection) url.openConnection();
      connection.setDoOutput(true);
      connection.setRequestMethod("POST");
      connection.setRequestProperty("Content-Type", "application/json");
      connection.setRequestProperty("Accept", "application/json");
      OutputStreamWriter writer = new OutputStreamWriter(connection.getOutputStream());
      JSONObject json = new JSONObject();
      try {
          json.put("email", "abc@gmail.com");
          json.put("name", "Test Group");
          json.put("description", "this is a test group");
      } catch (JSONException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
      }
      writer.write(json.toString());
      writer.flush();
      writer.close();
      log.info("connection.getResponseCode()"+connection.getResponseCode());        
  }
  </code></pre>
  
  <p>}</p>
  
  <p>But it is giving 401 response which is not expected.</p>
  
  <p>Where am i making mistake???</p>