openConnection(proxy) constructs the connection with a route. Set the HTTP method and body on the returned HttpURLConnection before initiating the request:

Proxy route = new Proxy(Proxy.Type.HTTP,
    new InetSocketAddress("proxy.example", 8080));
HttpURLConnection connection = (HttpURLConnection)
    URI.create("http://www.example.com/submit").toURL().openConnection(route);

try {
    connection.setConnectTimeout(5000);
    connection.setReadTimeout(15000);
    connection.setRequestMethod("POST");
    connection.setDoOutput(true);
    connection.setRequestProperty("Content-Type",
        "application/x-www-form-urlencoded; charset=UTF-8");

    byte[] form = "message=hello+proxy".getBytes(StandardCharsets.UTF_8);
    try (OutputStream out = connection.getOutputStream()) {
        out.write(form);
    }

    int status = connection.getResponseCode();
    System.out.println(status);
    InputStream response = status >= 400
        ? connection.getErrorStream() : connection.getInputStream();
    if (response != null) response.close();
} finally {
    connection.disconnect();
}

The example sends a small form, prints its status and closes an unused response stream. Replace that last step with the application's response-body handling when the body is needed.

The proxy hostname and port belong to route. For an allowed public form test with no proxy account, select the HTTP address from an entry in the HTTP proxy list. The URL remains the form endpoint. For dynamic form values, use URLEncoder to encode each value rather than joining unescaped input with equals signs and ampersands.

The output stream sends the prepared bytes. Read the status after writing and closing it, then choose the ordinary or error response stream as appropriate. A non-success HTTP response can contain useful application or proxy error content.

ХӀокхунах тера йаззамаш