Fix Invalid HTTP method Invalid HTTP method: SET
 at java.base/
 at java.base/
 at java.base/
 at HTTPExample.main(

ProtocolException invalid HTTP method occurs when you are trying to use an HTTP method that is invalid. Below is the list of valid HTTP methods that you can make use of depending upon what you are trying to achieve (usually associated with CURD at the server end),

  1. POST: Used to perform Create operation.
  2. GET: Used to peform Select operation.
  3. PUT: Used to peform Update/Replace operation.
  4. PATCH: Used to perform Update/Modify operation.
  5. DELETE: Used to perform Delete operation,
HttpURLConnection httpURLConnection = (HttpURLConnection) url.openConnection();
Java ProtocolException Invalid HTTP method
Java ProtocolException Invalid HTTP method

As you can I have used SET as the HTTP Request Method which is an invalid one!

Have Questions? Post them here!
Try Out Code2care Dev Tools:


Android Java Linux Microsoft Google Python macOS Notepad++ Microsoft Teams CSS PHP SharePoint Html Linux C Programs Bootstrap jQuery Sublime Android Studio Facebook Eclipse WhatsApp News MySQL Json HowTos JavaScript FTP S3


Code2care is an initiative to publish and share varied knowledge in programming and technical areas gathered during day-to-day learnings and development activities.

Students and Software Developers can leverage this portal to find solutions to their various queries without re-inventing the wheel by referring to our easy to understand posts. Technical posts might include Learnings, Tutorials, Trouble-Shooting steps, Video Tutorials, Code Snippets, How Tos, Blogs, Articles, etc.
🎉 We are celebrating the 10th years of Code2care! Thank you for all your support! We hope we made a difference.
We strong support Gender Equality & Diversity.

We stand in solidarity with Ukraine - Make a donation to UNHCR -