HttpURLConnection POST, conn.getOutputStream() throwing Exception

前端 未结 2 1779
感情败类
感情败类 2021-01-14 10:56

I want to make a POST by using HttpURLConnection. I am trying this in 2 ways, but I always get an excetion when doing: conn.getOutputStream();

The excep

2条回答
  •  我在风中等你
    2021-01-14 11:20

    Without establishing the connection (which in this case requires 1 more step to be performed ie connect), transfer is not possible. connect() should be called after the connection is configured (ie after being done with the set***() on the connection).

    What is missing is:

    conn.connect();
    

提交回复
热议问题