简体   繁体   中英

Java HTTP/HTTPS post from app 1 to app 2 in different server

I have to develop a java application which has to do a http post to a different application. Both the application does not have a JSP page as a front end. (Http POST from servlet to servlet).

When I was exploring options for this I managed to find

response.sendRedirect("http://localhost:8081/appname/servletname?var1=&var2=?...);

But this is based on http get. How do I do the same using HTTP post?

Thanks Arun Kumar

The code you found is for redirecting an incoming request to another location. The client ends up sending a new request to the new URL. This is not what you want.

You can make an HTTP request using the class java.net.URL . You can then get an OutputStream and write your POST data in the body of the request. You will have to encode all your data values with java.net.URLEncoder.

I think there is a library in Apache commons that makes this easier.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM