Fuel: Cannot access request header fields after connection is set

Created on 26 Aug 2017  路  16Comments  路  Source: kittinunf/fuel

Attempting to execute:

"http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en".httpGet().response { request, response, result -> 
     println(request)
     println(response)
}

produces:

java.lang.IllegalStateException: Cannot access request header fields after connection is set
     at com.github.kittinunf.fuel.toolbox.HttpClient.executeRequest(HttpClient.kt:69)
     at com.github.kittinunf.fuel.core.requests.TaskRequest.call(TaskRequest.kt:16)
     at com.github.kittinunf.fuel.core.requests.AsyncTaskRequest.call(AsyncTaskRequest.kt:13)
     at com.github.kittinunf.fuel.core.requests.AsyncTaskRequest.call(AsyncTaskRequest.kt:6)
     at java.util.concurrent.FutureTask.run(FutureTask.java:237)
     at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1133)
     at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:607)
     at com.github.kittinunf.fuel.core.FuelManager$executor$2$1$1.run(FuelManager.kt:49)
     at java.lang.Thread.run(Thread.java:761)

Using the cUrlLoggingRequestInterceptor I got the following curl that when executed on a terminal it works:

curl -i -H "Accept-Encoding:compress;q=0.5, gzip;q=1.0" "http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en"

bug

Most helpful comment

I also faced this exception. But it happens only when i enable advanced profiling. With disabled profiler it works well.

All 16 comments

I cannot reproduce your error. What I did is following;

Go to sample folder in Fuel project and change the implementation of https://github.com/kittinunf/Fuel/blob/508dd2e05b7b88d1a3edb3fdc63d1861cecd89fd/sample/src/main/kotlin/com/example/fuel/MainActivity.kt#L43

to the following;

screen shot 2017-08-27 at 3 06 15

Then, the emulator show the result as expected. (I clicked button multiple times)

screenshot_1503770814

Is there anything more into this so I can reproduce the error?

Hey @kittinunf, Seems I'm not the only one. #229 is having the exact same exception. I'm using:

  • Fuel's latest version
  • Android Studio 3.0 Beta 3
  • Kotlin 1.1.4-2
  • com.android.tools.build:gradle:3.0.0-beta3
  • compileSdkVersion 26
  • targetSdkVersion 26
  • buildToolsVersion "26.0.0"

I tried the sample and it's the same. I didn't even had to modify it, the same isn't working at all.

Also, Fuel seems to be the problem here. I tried both, Retrofit and OkHttp, and all of them are working fine.

Author of #229 here.

Quite the same situation. Other libraries work fine, only the first request with Fuel succeeded any subsequent one fails with this error.

Hi, all! @apognu or @mradzinski, if you can reproduce this error may be you can to try fix one and create merge request. We will glad to merge it.

@KucherenkoIhor, well, I actually had to move away from Fuel due to this issue. As for reproducing it: Just download the sample from this repo, update its gradle & kotlin dependency and run it; Hint: It'll fail.

@mradzinski First of all, I believe the sample fails because of other issues. Let's us focus on your issue first, shall we?

I will try to mimic your situation as much as possible.

I have created this test repo. The gist of MainActivity.kt is just

        fab.setOnClickListener {
            "http://api.forismatic.com/api/1.0/?method=getQuote&format=json&lang=en".httpGet()
                    .responseString { request, response, result ->
                        text.append(result.toString())
                    }
        }

I have pushed the commit that I have tested with your API endpoint. But, I am unable to reproduce your issue.

The emulator shows the result from the API as expected.

screenshot_1503925861

If you don't mind, could you please try in that repo and show it to me whether you could make it work or not. if you could please help me hunt down the issue, I would be much appreciated.

Is there any update on your side @mradzinski ?

I have exactly the same problem, but that isn't appeard whenever, i can't figure out where it depends.

Hello there, this problem happen on my Pixel (Android 8.0) and not happen on Samsung S7 (Android 7)

@PichuChen that is a bit weird. Do you know what could possibly trigger the problem? I have made the repo here. If you do have time, even better if you could come up with a test that fails?

@kittinunf Testing result on Pixel is successful, is really weird...
I will try to copy my code to reproduce this problem.

I also faced this exception. But it happens only when i enable advanced profiling. With disabled profiler it works well.

I've faced the same problem a few days ago. From my point of view there was a problem with the ide (android studio 3.1.3) and the used kotlin plugin. I could solve it by updating kotlin and the plugin to 1.2.50 and then all used com.android.support* libraries to 27.1.1. In addition i've cleaned my project entirely (fresh clone of repo) after a new build of the application the problem disappeared.

is this still an issue?

Let's close this as it looks quite stale to me.

Was this page helpful?
0 / 5 - 0 ratings