我有一个 Android 应用程序需要在连接中设置请求属性。这是我的代码:
URL url = new URL(sUrl);
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestProperty("cookie", cookievalue);
connection.connect();
当我打电话给setRequestProperty
方法启动异常:
java.lang.IllegalStateException: Cannot set request property after connection is made
有没有一种方法可以在不使用url.openConnection()
?
Here url.openCOnnection()
将打开与此 URL 引用的资源的新连接。
在这里,您再次通过调用打开连接 url.connect()
方法。所以删除它
Check this.. http://developer.android.com/reference/java/net/HttpURLConnection.html对于示例示例...
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)