Java: send GET PUT POST to external API and get response
I am relatively new to JAVA and am trying to create a back-end application that will call another server that has data present.
I need to perform GET, POST, PUT and PATCH operations (can work without PATCH) to an external server on the intranet. I can take advantage of a vulnerable service using a postman application (using a custom header), but I want to perform a similar action from my Java code, get the output on my Tomcat Server.
I have limitations in changing dependencies with a POM file or adding banners to a library, so I am looking for a non-Jersey solution.
source to share
You can use HttpURLConnection (which extends URLConnection ) to handle HTTP requests, and these classes are part of the JDK itself, so you don't need external jar files, I suggest you look here to learn about it and look here for an example.
Most of the places I'm looking for give me an answer for GET. i see some POSTs too, but my requirement is mostly for PUT.
To place transactions PUT
, DELETE
etc. http, you can use httpConnectionObj.setRequestMethod("PUT")
or httpConnectionObj.setRequestMethod("DELETE")
as mentioned in the example here .
source to share