今天测试时,发现有个地方没修改过代码,但是却出现一个奔溃问题。
java.lang.IllegalStateException: Cannot access request header fields after connection is set
at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getRequestProperties(HttpURLConnectionImpl.java:231)
at com.android.tools.profiler.support.network.httpurl.TrackedHttpURLConnection.getRequestProperties(TrackedHttpURLConnection.java:204)
at com.android.tools.profiler.support.network.httpurl.TrackedHttpURLConnection.trackPreConnect(TrackedHttpURLConnection.java:63)
at com.android.tools.profiler.support.network.httpurl.TrackedHttpURLConnection.getInputStream(TrackedHttpURLConnection.java:354)
at com.android.tools.profiler.support.network.httpurl.HttpURLConnection$.getInputStream(HttpURLConnection$.java:207)
通过多次尝试,发现网上有个方法可以解决:
将inputStream = connection.getInputStream();
放到int fileLength = connection.getContentLength();
前面即可。
之前一直没问题,但是升级了buildToolsVersion
和compileSdkVersion
版本就出现此问题了。
网友评论