/** * Send a post request * @param url Url as string * @param body Request body as string * @return response Response as string * @throws IOException */ public static String post(String url, String body) throws IOException { return post(url, body, null); }
return post(url, body, headers);
private void sendAuthorizationToAgent(String agentUrl, String agentMethod, ObjectNode auth) throws IOException { JSONRequest rpcRequest = new JSONRequest(agentMethod, auth); HttpUtil.post(agentUrl, rpcRequest.toString()); }
/** * Create a task list * @param taskList JSON structure containing a taskList * @return JSON sturcture with created tasklist */ public ObjectNode createTaskList(@Name("taskList") ObjectNode taskList) throws Exception { String url = CALENDAR_URI + "users/@me/lists"; // perform POST request ObjectMapper mapper = JOM.getInstance(); String body = mapper.writeValueAsString(taskList); Map<String, String> headers = getAuthorizationHeaders(); headers.put("Content-Type", "application/json"); String resp = HttpUtil.post(url, body, headers); ObjectNode createdTaskList = mapper.readValue(resp, ObjectNode.class); // check for errors if (createdTaskList.has("error")) { ObjectNode error = (ObjectNode)createdTaskList.get("error"); throw new JSONRPCException(error); } logger.info("createTaskList=" + JOM.getInstance().writeValueAsString(createdTaskList)); return createdTaskList; }
Map<String, String> headers = getAuthorizationHeaders(); headers.put("Content-Type", "application/json"); String resp = HttpUtil.post(url, body, headers); ObjectNode createdTask = mapper.readValue(resp, ObjectNode.class);
Map<String, String> headers = getAuthorizationHeaders(); headers.put("Content-Type", "application/json"); String resp = HttpUtil.post(url, body, headers); ObjectNode response = mapper.readValue(resp, ObjectNode.class);
Map<String, String> headers = getAuthorizationHeaders(); headers.put("Content-Type", "application/json"); String resp = HttpUtil.post(url, body, headers); ObjectNode createdEvent = mapper.readValue(resp, ObjectNode.class);