<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.8.0</version>
</dependency>
public static String postXml(String url, String xmlStr){
RequestBody body = RequestBody.create(MediaType.parse("application/xml;charset=utf-8"), xmlStr);
Request requestOk = new Request.Builder().url(url).post(body).build();
OkHttpClient client = new OkHttpClient().newBuilder().connectTimeout(10000, TimeUnit.MILLISECONDS)
.readTimeout(10000, TimeUnit.MILLISECONDS).build();
String xmlString = "";
try {
Response response = client.newCall(requestOk).execute();
xmlString = response.body().string();
} catch (Exception e) {
e.printStackTrace();
return e.getMessage();
}
return xmlString;
}