protected HttpRequestWithBody post(String path) { log.info("[POST] {}", (origin + path)); return Unirest.post(origin + path); }
protected String postBodyString(String path) throws Exception { log.info("[POST] {}", (origin + path)); return Unirest.post(origin + path).asString().getBody(); }
public static JSONObject post(String urlCommand, String body) { log.trace("post: %s body: %s", urlCommand, body); HttpResponse<JsonNode> jsonResponse = null; JSONObject response = null; try { jsonResponse = Unirest.post(urlBase + urlCommand) .header("accept", "application/json") .header("content-type", "application/json") .body(body) .asJson(); } catch (UnirestException e) { log.error("post(): %s", e.getMessage()); } String responseBody = "null"; if (SX.isNotNull(jsonResponse)) { responseBody = jsonResponse.getBody().toString(); response = SXJson.makeObject(responseBody); } log.trace("post: response: %s", responseBody); return response; }
protected void logout() throws IOException { try { Unirest.post(serverUrl + "v1/logout").asString(); this.authToken = ""; this.userId = ""; } catch (UnirestException e) { throw new IOException(e); } }
public static HttpRequestWithBody post(String url) { return Unirest.post(ClientManager.lookup(url)); }
public void create() { JSONObject jsonOut = new JSONObject(); jsonOut.put("user", user) .put("key", key) .put("nick", session); RequestBodyEntity post = Unirest.post("https://cleverbot.io/1.0/create").header("Content-Type", "application/json") .body(jsonOut.toString()); }
public String ask(String query) throws UnirestException { JSONObject jsonOut = new JSONObject(); jsonOut.put("user", user) .put("key", key) .put("nick", session) .put("text", query); RequestBodyEntity post = Unirest.post("https://cleverbot.io/1.0/ask").header("Content-Type", "application/json") .body(jsonOut.toString()); JSONObject json = post.asJson().getBody().getObject(); return json.getString("response"); } }
public int createImposter(Imposter imposter) { try { HttpResponse<JsonNode> response = Unirest.post(baseUrl + "/imposters").body(imposter.toString()).asJson(); return response.getStatus(); } catch (UnirestException e) { return 500; } }
public JSONArray postA(String url, JSONObject body) { return toArray(addHeaders(Unirest.post(url)).body(body.toString())); }
public void createApplication() { if (!active) { return; } try { JSONObject applicationJson = getJSonResponse(Unirest.post(url + APPLICATION_API_URL) .field("name", SeleniumTestsContextManager.getApplicationName())); applicationId = applicationJson.getInt("id"); } catch (UnirestException | JSONException e) { throw new SeleniumRobotServerException("cannot create application", e); } }
/** * dumps a string to hastebin * * @param message the text to send * @return key how to find it */ private static String handleHastebin(String message) throws UnirestException { return Unirest.post("https://hastebin.com/documents").body(message).asJson().getBody().getObject().getString("key"); } }
public static void main(String[] args) throws UnirestException { HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post") .header("accept", "application/json") .field("parameter", "value") .field("file", new File("/tmp/file")) .asJson(); System.out.println(jsonResponse.getBody().toString()); } }
public static void main(String[] args) throws UnirestException { HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post") .header("accept", "application/json") .body("{\"parameter\":\"value\", \"foo\":\"bar\"}") .asJson(); System.out.println(jsonResponse.getBody().toString()); } }
public void createEnvironment() { if (!active) { return; } try { JSONObject envJson = getJSonResponse(Unirest.post(url + ENVIRONMENT_API_URL) .field("name", SeleniumTestsContextManager.getThreadContext().getTestEnv())); environmentId = envJson.getInt("id"); } catch (UnirestException | JSONException e) { throw new SeleniumRobotServerException("cannot create environment", e); } }
public static UserProfilePhotos createUserProfilePhotos(long user_id, TelegramBot telegramBot) { try { JSONObject json = Unirest.post(telegramBot.getBotAPIUrl() + "getUserProfilePhotos") .queryString("user_id", user_id).asJson().getBody().getObject(); if(json.getBoolean("ok")) { return new UserProfilePhotosImpl(json.getJSONObject("result")); } } catch (UnirestException e) { e.printStackTrace(); } return null; }
private HttpRequest buildUnirest(WorkingContext workingContext) { String url = String.format("%s%s", PROJECTOXFORD_AI, workingContext.getPathBuilt()); switch (workingContext.getHttpMethod()) { case GET: return Unirest.get(url); case PUT: return Unirest.put(url); case DELETE: return Unirest.delete(url); case PATCH: return Unirest.patch(url); } return Unirest.post(url); }
static public JsonNode post(String url, JSONObject json) { HttpResponse<JsonNode> jsonResponse = null; try { jsonResponse = Unirest.post(url).header("content-type", "application/json").body(json).asJson(); } catch (UnirestException e) { unirestCrash(e); } return jsonResponse.getBody(); }
@Test public void shouldCreateAnImposter() throws UnirestException { Imposter imposter = new Imposter(); when(Unirest.post(Client.DEFAULT_BASE_URL + "/imposters")).thenReturn(requestWithBody); when(requestWithBody.body(imposter.toString())).thenReturn(requestBodyEntity); when(requestBodyEntity.asJson()).thenReturn(httpResponse); when(httpResponse.getStatus()).thenReturn(Integer.valueOf(201)); int statusCode = client.createImposter(imposter); assertThat(statusCode).isEqualTo(201); }
public static void main(String[] args) throws UnirestException { HttpResponse<JsonNode> jsonResponse = Unirest.post("http://httpbin.org/post") .header("accept", "application/json") .queryString("apiKey", "123") .field("parameter", "value") .field("foo", "bar") .asJson(); System.out.println(jsonResponse.getBody().toString()); } }
default HttpResponse<RTypeDefinition> createTdef(String namespace, RTypeDefinition tdef) throws UnirestException, KevoreeRegistryException { // be sure user is logged-in / refresh token if necessary / throws otherwise this.ensureLogin(); // POST tdef return Unirest.post(this.baseUrl() + "/api/namespaces/{namespace}/tdefs") .header("Authorization", "Bearer " + config().getString("user.access_token")) .header("Content-Type", "application/json") .routeParam("namespace", namespace) .body(tdef) .asObject(RTypeDefinition.class); }