Here's an example how to do it with java.net.URLConnection:

String url ="http://example.com";
String charset ="UTF-8";
String param1 =URLEncoder.encode("param1", charset);
String param2 =URLEncoder.encode("param2", charset);
String query =String.format("param1=%s&param2=%s", param1, param2);

URLConnection urlConnection =new URL(url).openConnection();
urlConnection
.setUseCaches(false);
urlConnection
.setDoOutput(true);// Triggers POST.
urlConnection
.setRequestProperty("accept-charset", charset);
urlConnection
.setRequestProperty("content-type","application/x-www-form-urlencoded");

OutputStreamWriter writer =null;
try{
    writer
=newOutputStreamWriter(urlConnection.getOutputStream(), charset);
    writer
.write(query);// Write POST query string (if any needed).
}finally{
   
if(writer !=null)try{ writer.close();}catch(IOException logOrIgnore){}
}

InputStream result = urlConnection.getInputStream();
// Now do your thing with the result.
// Write it into a String and put as request attribute
// or maybe to OutputStream of response as being a Servlet behind `jsp:include`.

相关文章:

  • 2022-12-23
  • 2022-01-05
  • 2022-01-01
  • 2021-04-27
  • 2022-12-23
  • 2021-10-20
  • 2021-05-20
  • 2021-05-25
猜你喜欢
  • 2021-12-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-05
  • 2021-07-25
  • 2021-10-08
相关资源
相似解决方案