Cannot access request header fie

作者: chenxuxu | 来源:发表于2018-06-22 16:56 被阅读34次

    今天测试时,发现有个地方没修改过代码,但是却出现一个奔溃问题。

    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();前面即可。
    之前一直没问题,但是升级了buildToolsVersioncompileSdkVersion版本就出现此问题了。

    相关文章

      网友评论

        本文标题:Cannot access request header fie

        本文链接:https://www.haomeiwen.com/subject/xmakyftx.html