In lack of information what kind of server this might be, I've found this
OkHttpClient client = new OkHttpClient();
OutputStream out = null;
try {
URL url = new URL("http://www.example.com");
HttpURLConnection connection = client.open(url);
for (Map.Entry<String, String> entry : multipart.getHeaders().entrySet()) {
connection.addRequestProperty(entry.getKey(), entry.getValue());
}
connection.setRequestMethod("POST");
// Write the request.
out = connection.getOutputStream();
multipart.writeBodyTo(out);
out.close();
// Read the response.
if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) {
throw new IOException("Unexpected HTTP response: "
+ connection.getResponseCode() + " " + connection.getResponseMessage());
}
}
finally {
try { if (out != null) out.close(); }
catch (Exception e) {}
}
I assume that the deprecated/outdated library you mentioned would be ApacheHttpClient, therefore I recommend OkHttp
(that is using HttpUrlConnection
I believe) instead.
To add OkHttp as dependency you can edit your build.gradle
like:
dependencies {
//some other dependencies
compile 'com.squareup.okhttp:okhttp:2.7.2'
}
Available versions can be found here: mvnrepository (no need to download them manually, just add them like above, gradle will download them itself)