In java, how to create HttpsURLConnection or HttpURLConnection based on the url?

前端 未结 2 1976
悲&欢浪女
悲&欢浪女 2021-01-02 00:01

I\'m working on a project where I\'m creating a class to run http client requests (my class acts as a client). It takes in a url and a request method (GET, POST, PUT, etc)

2条回答
  •  孤独总比滥情好
    2021-01-02 00:25

    HttpsURLConnection extends HttpUrlConnection, so you do not need the HttpsUrlConnection, you can just do

    HttpURLConnection conn = (HttpURLConnection) url.openConnection();
    

提交回复
热议问题