The warning disappears if I just remove setRequestMethod. However, if I need to create a POST request later I still need to use setRequestMethod. How can I use setRequestMethod without getting these warnings?
Just so you don’t get too worried, you safely ignore these warnings for some period of time. The code keeps working. It’s just that after Java 9 some things are more strict.
You can get rid of the warning by using ^HttpURLConnection connection and (import java.net.HttpURLConnection). Reflection is just picking a class that it isn’t “allowed” to technically.