setRequestProperty throwing java.lang.IllegalStateException: Cannot set request property after connection is made

前端 未结 9 1856
我在风中等你
我在风中等你 2020-12-17 17:35

I am getting java.lang.IllegalStateException:

java.lang.IllegalStateException: Cannot set request property after connection is made error w

9条回答
  •  心在旅途
    2020-12-17 18:23

    please check below code

    HttpURLConnection httpcon = (HttpURLConnection) ((new URL("a url").openConnection()));
    httpcon.setDoOutput(true);
    httpcon.setRequestProperty("Content-Type", "application/json");
    httpcon.setRequestProperty("Accept", "application/json");
    httpcon.setRequestMethod("POST");
    httpcon.connect();
    

提交回复
热议问题