khttp icon indicating copy to clipboard operation
khttp copied to clipboard

IllegalStateException: Cannot access request header fields after connection is set

Open sbrl opened this issue 6 years ago • 3 comments

I've stumbled upon what I think is a bug. If I do something like this:

khttp.get(
	Info.RootUrl,
	params = mapOf(
		"action" to "status",
		"minified" to "true"
	),
	headers = mapOf(
		"Accept" to "application/json"
	),
	allowRedirects = false,
	cookies = mapOf( ..... )
)

...then I'm getting the following exception:

Process: com.sbrl.peppermint, PID: 10133
java.lang.IllegalStateException: Cannot access request header fields after connection is set
 at com.android.okhttp.internal.huc.HttpURLConnectionImpl.getRequestProperties(HttpURLConnectionImpl.java:232)
 at com.android.okhttp.internal.huc.DelegatingHttpsURLConnection.getRequestProperties(DelegatingHttpsURLConnection.java:182)
 at com.android.okhttp.internal.huc.HttpsURLConnectionImpl.getRequestProperties(Unknown Source:0)
 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.connect(TrackedHttpURLConnection.java:126)
 at com.android.tools.profiler.support.network.httpurl.HttpsURLConnection$.connect(HttpsURLConnection$.java:366)
 at khttp.responses.GenericResponse.openRedirectingConnection$khttp(GenericResponse.kt:125)
 at khttp.responses.GenericResponse.getConnection(GenericResponse.kt:163)
 at khttp.responses.GenericResponse.getRaw(GenericResponse.kt:207)
 at khttp.responses.GenericResponse.getContent(GenericResponse.kt:216)
 at khttp.responses.GenericResponse.init$khttp(GenericResponse.kt:377)
 at khttp.KHttp.request(KHttp.kt:61)
 at khttp.KHttp.get(KHttp.kt:30)
 at khttp.KHttp.get$default(KHttp.kt:29)

I really don't understand what's going on here. Sometimes it works once but not twice in a row, and others it doesn't :-( It always comes down to the khttp.get() call above.

Thoughts?

sbrl avatar Mar 30 '18 16:03 sbrl

Same problem here. This happens to me only on emulator (Nexus 5X)

kaczorrrro avatar May 16 '18 12:05 kaczorrrro

Same problem as well, as @kaczorrrro said, on device works fine, but I can't use the emualtor.

mmattax avatar Jun 03 '18 15:06 mmattax

Thank you for including code and a stack trace, working to repro and fix.

bbeaupain avatar Jun 06 '19 16:06 bbeaupain