Issues HTTP POST request, returns response body as string.

@param endpoint endpoint of request url
@param params   request line parameters

@return response body

@throws IOException in case of any IO related issue
421681
public String post(String endpoint, String params) throws IOException {
        return this.post(endpoint, params, "");
    }
1141489
public void post(String jsonBody, Integer expectedResponseCode) throws IOException {
    HttpURLConnection conn = getUrlConnection();

    try {
      // send post request with json body for the topology
      if (!NetworkUtils.sendHttpPostRequest(conn, NetworkUtils.JSON_TYPE, jsonBody.getBytes())) {
        throw new IOException("Failed to send POST to " + endpointURI);
      }

      // check the response
      if (!NetworkUtils.checkHttpResponseCode(conn, expectedResponseCode)) {
        byte[] bytes = NetworkUtils.readHttpResponse(conn);
        LOG.log(Level.SEVERE, "Failed to send POST request to endpoint");
        LOG.log(Level.SEVERE, new String(bytes));
        throw new IOException("Unexpected response from connection. Expected "
            + expectedResponseCode + " but received " + conn.getResponseCode());
      }
    } finally {
      conn.disconnect();
    }
  }
932001
@Override
	public <T extends Resource> T post(final String uri, final Parameters params) {
		return doRequest(uri).set(params).post();
	}
454078
public static NanoResponse serve(String url, String method, Properties header, Properties parms, String post_body) {
    boolean hideParameters = true;
    try {
      // Jack priority for user-visible requests
      Thread.currentThread().setPriority(Thread.MAX_PRIORITY - 1);

      RequestType type = RequestType.requestType(url);
      RequestUri uri = new RequestUri(method, url);

      // Log the request
      hideParameters = maybeLogRequest(uri, header, parms);

      // For certain "special" requests that produce non-JSON payloads we require special handling.
      NanoResponse special = maybeServeSpecial(uri);
      if (special != null) return special;

      // Determine the Route corresponding to this request, and also fill in {parms} with the path parameters
      Route route = routesTree.lookup(uri, parms);

      //----- DEPRECATED API handling ------------
      // These APIs are broken, because they lead users to create invalid URLs. For example the endpoint
      //   /3/Frames/{frameid}/export/{path}/overwrite/{force}
      // is invalid, because it leads to URLs like this:
      //   /3/Frames/predictions_9bd5_GLM_model_R_1471148_36_on_RTMP_sid_afec_27/export//tmp/pred.csv/overwrite/TRUE
      // Here both the {frame_id} and {path} usually contain "/" (making them non-tokens), they may contain other
      // special characters not valid within URLs (for example if filename is not in ASCII); finally the use of strings
      // to represent booleans creates ambiguities: should I write "true", "True", "TRUE", or perhaps "1"?
      //
      // TODO These should be removed as soon as possible...
      if (url.startsWith("/3/Frames/")) {
        // /3/Frames/{frame_id}/export/{path}/overwrite/{force}
        if ((url.toLowerCase().endsWith("/overwrite/true") || url.toLowerCase().endsWith("/overwrite/false")) && url.contains("/export/")) {
          int i = url.indexOf("/export/");
          boolean force = url.toLowerCase().endsWith("true");
          parms.put("frame_id", url.substring(10, i));
          parms.put("path", url.substring(i+8, url.length()-15-(force?0:1)));
          parms.put("force", force? "true" : "false");
          route = findRouteByApiName("exportFrame_deprecated");
        }
        // /3/Frames/{frame_id}/export
        else if (url.endsWith("/export")) {
          parms.put("frame_id", url.substring(10, url.length()-7));
          route = findRouteByApiName("exportFrame");
        }
        // /3/Frames/{frame_id}/columns/{column}/summary
        else if (url.endsWith("/summary") && url.contains("/columns/")) {
          int i = url.indexOf("/columns/");
          parms.put("frame_id", url.substring(10, i));
          parms.put("column", url.substring(i+9, url.length()-8));
          route = findRouteByApiName("frameColumnSummary");
        }
        // /3/Frames/{frame_id}/columns/{column}/domain
        else if (url.endsWith("/domain") && url.contains("/columns/")) {
          int i = url.indexOf("/columns/");
          parms.put("frame_id", url.substring(10, i));
          parms.put("column", url.substring(i+9, url.length()-7));
          route = findRouteByApiName("frameColumnDomain");
        }
        // /3/Frames/{frame_id}/columns/{column}
        else if (url.contains("/columns/")) {
          int i = url.indexOf("/columns/");
          parms.put("frame_id", url.substring(10, i));
          parms.put("column", url.substring(i+9));
          route = findRouteByApiName("frameColumn");
        }
        // /3/Frames/{frame_id}/summary
        else if (url.endsWith("/summary")) {
          parms.put("frame_id", url.substring(10, url.length()-8));
          route = findRouteByApiName("frameSummary");
        }
        // /3/Frames/{frame_id}/light
        else if (url.endsWith("/light")) {
          parms.put("frame_id", url.substring(10, url.length()-"/light".length()));
          route = findRouteByApiName("lightFrame");
        }
        // /3/Frames/{frame_id}/columns
        else if (url.endsWith("/columns")) {
          parms.put("frame_id", url.substring(10, url.length()-8));
          route = findRouteByApiName("frameColumns");
        }
        // /3/Frames/{frame_id}
        else {
          parms.put("frame_id", url.substring(10));
          route = findRouteByApiName(method.equals("DELETE")? "deleteFrame" : "frame");
        }
      } else if (url.startsWith("/3/ModelMetrics/predictions_frame/")){
        route = findRouteByApiName("makeMetrics");
      }
      //------------------------------------------

      if (route == null) {
        // if the request is not known, treat as resource request, or 404 if not found
        if (uri.isGetMethod())
          return getResource(type, url);
        else
          return response404(method + " " + url, type);

      } else {
        Schema response = route._handler.handle(uri.getVersion(), route, parms, post_body);
        PojoUtils.filterFields(response, (String)parms.get("_include_fields"), (String)parms.get("_exclude_fields"));
        return serveSchema(response, type);
      }

    }
    catch (H2OFailException e) {
      H2OError error = e.toH2OError(url);
      Log.fatal("Caught exception (fatal to the cluster): " + error.toString());
      throw H2O.fail(serveError(error).toString());
    }
    catch (H2OModelBuilderIllegalArgumentException e) {
      H2OModelBuilderError error = e.toH2OError(url);
      Log.warn("Caught exception: " + error.toString());
      return serveSchema(new H2OModelBuilderErrorV3().fillFromImpl(error), RequestType.json);
    }
    catch (H2OAbstractRuntimeException e) {
      H2OError error = e.toH2OError(url);
      Log.warn("Caught exception: " + error.toString());
      return serveError(error);
    }
    catch (AssertionError e) {
      H2OError error = new H2OError(
              System.currentTimeMillis(),
              url,
              e.toString(),
              e.toString(),
              HttpResponseStatus.INTERNAL_SERVER_ERROR.getCode(),
              new IcedHashMapGeneric.IcedHashMapStringObject(),
              e);
      Log.err("Caught assertion error: " + error.toString());
      return serveError(error);
    }
    catch (Exception e) {
      // make sure that no Exception is ever thrown out from the request
      H2OError error = new H2OError(e, url);
      // some special cases for which we return 400 because it's likely a problem with the client request:
      if (e instanceof IllegalArgumentException || e instanceof FileNotFoundException || e instanceof MalformedURLException)
        error._http_status = HttpResponseStatus.BAD_REQUEST.getCode();
      String parmsInfo = hideParameters ? "<hidden>" : String.valueOf(parms);
      Log.err("Caught exception: " + error.toString() + ";parms=" + parmsInfo);
      return serveError(error);
    }
  }
412184
def post(self, endpoint, params=None, version='1.1', json_encoded=False):
        """"""
        return self.request(endpoint, 'POST', params=params, version=version, json_encoded=json_encoded)
591505
def post_request(self, endpoint, body=None, timeout=-1):
        
        return self.request('POST', endpoint, body, timeout)
256939
public String delete(String endpoint, String params) throws IOException {
        return this.delete(endpoint, params, "");
    }
496937
def request(post_body, headers)
      response = @client.post(endpoint, post_body, headers)
      return { :status => response.status, :body => response.content, :content_type => response.contenttype }
    end
354644
protected void handleEndpointRequest(HttpServletRequest request, HttpServletResponse response,
			ServletContext servletContext) throws IOException {
		JwtRequest jwtRequest = getJwtRequest(request, response);
		if (jwtRequest == null) {
			// Error redirect already taken care of
			return;
		}

		String jwtConfigId = jwtRequest.getJwtConfigId();
		JwtConfig jwtConfig = getJwtConfig(response, jwtConfigId);
		if (jwtConfig == null) {
			// Error redirect already taken care of
			return;
		}

		EndpointType endpointType = jwtRequest.getType();
		handleJwtRequest(request, response, servletContext, jwtConfig, endpointType);

	}
222564
public function requestGet($endpoint, $params = array(), $headers = array())
    {
        return $this->getClient()->get($endpoint, $params, $headers);
    }
450186
public Object getRequest(String restUrl, Map<String, String> params) throws IOException, WebServiceException {
		HttpURLConnection conn = null;
		try {
			// Make the URL
			urlString = new StringBuilder(this.host).append(restUrl);
			urlString.append(this.makeParamsString(params, true));
		    LOGGER.debug("Doing HTTP request: GET [{}]", urlString.toString());
			// Connection configuration
//            Proxy proxy = DEBUG_HTTP ? new Proxy(Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", 8008)) : Proxy.NO_PROXY;			
            URL url = new URL(urlString.toString());
			conn = (HttpURLConnection) url.openConnection();
			conn.setRequestMethod(HttpMethod.GET.name());
			conn.setRequestProperty("Connection", "Keep-Alive");

			// Gets the response
			return this.readResponse(restUrl, conn);
        } catch (WebServiceException e) {
            LOGGER.debug("WebServiceException catched. Request error", e);
            throw e;
		} catch (IOException e) {
            LOGGER.debug("IOException catched. Request error", e);
			throw e;
		} catch (Exception e) {
            LOGGER.debug("Exception catched, throwing a new IOException. Request error", e);
            throw new IOException(e.getLocalizedMessage());
		} finally {
			if (conn != null) {
				conn.disconnect();
			}
		}
	}
1348200
protected function makeGetRequest($endpoint, array $params) {
        // Constructs get url
        // e.g:
        // endpoint = 'ip-address/report'
        //
        // params => array(
        //                'ip'       => '192.168.2.1',
        //                'apikey'   => 'supersecureapikey'
        //            )
        //
        // It maps to:
        // https://www.virustotal.com/vtapi/v2/ip-address/report?ip=192.168.2.1&apikey=supersecureapikey
        try {
            $url = self::API_ENDPOINT . $endpoint . '?'. http_build_query($params);
            $response = $this->_client->get($url);
            $this->validateResponse($response->getStatusCode());
            return $response;
        } catch(ClientException $e) {
            $this->validateResponse($e->getResponse()->getStatusCode());
        }
    }
680868
def handleHttpPost(request, endpoint):
    
    if request.mimetype and request.mimetype != MIMETYPE:
        raise exceptions.UnsupportedMediaTypeException()
    request = request.get_data()
    if request == '' or request is None:
        request = '{}'
    responseStr = endpoint(request)
    return getFlaskResponse(responseStr)
183864
public RestResponse postJson(final String uri, final String params)
            throws IOException, AppPlatformException {
        return requestJson(getPath(uri), HttpPost.METHOD_NAME, params);
    }
1223328
public String putJson(String endpoint, String params, JSONObject json) throws IOException {
        return this.putJson(endpoint, params, json, "");
    }
1012947
public function request($endpoint, $method, $data = [], $parameters = [])
    {
        // Initialize cURL.
        $this->ch = \curl_init();

        // Set request args.
        $request = $this->createRequest($endpoint, $method, $data, $parameters);

        // Default cURL settings.
        $this->setDefaultCurlSettings();

        // Get response.
        $response = $this->createResponse();

        // Check for cURL errors.
        if (\curl_errno($this->ch)) {
            throw new HttpClientException('cURL Error: ' . \curl_error($this->ch), 0, $request, $response);
        }

        \curl_close($this->ch);

        return $this->processResponse();
    }
1232091
function ApiClient(endpoint) {
    if (endpoint.length > 0 && endpoint.slice(-1) != "/") {
        endpoint += "/";
    }
    
    this.endpoint = endpoint;
    this.namespace = null;
}