Cannot set request property after connection is made

我的代码:

URL url = new URL("http://169.254.21.113:8080/maven/user.do?method="+method+parms);//json地址
connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.setRequestProperty("Content-Length",parms.length()+"");//异常发生

错误原因:

我调试的时候,添加了返回码connection.getResponseCode()的变量监视;影响到编译器的判断;

解决方案:

删掉此变量监视;

 

 

参考来源:https://stackoverflow.com/questions/22320418/setrequestproperty-throwing-java-lang-illegalstateexception-cannot-set-request

你可能感兴趣的:(Java,Android)