Open roysG opened 3 years ago
We have run into the same issue. From what I can tell reading the library's code, this is what is happening:
responseStatusCode()
.post()
returns the error specifying that it has been called in an unexpected state (-2). This is because in startRequest
, the state is reset in some cases (if (iState == eReadingBody || iState == eReadingChunkLength || iState == eReadingBodyChunk)
), but since iState is eReadingStatusCode
, it is not reset, resulting in an early return with -2.Is there a good reason as to why the state is only reset in those three cases? Might simply adding an || iState == eReadingStatusCode
solve the problem, or will that have other unexpected side effects? (Or am I wrong in my reconstruction altogether?)
@roysG did you perhaps find another way to solve or work around the issue?
We did find a very simple workaround: simply construct new HttpClient
objects before each post
rather than keeping a global HttpClient object.
I actually think that this is generally more sensible: HTTP is stateless, so keeping a global (stateful) HttpClient
object is error-prone and logically inconsistent. It might be better practice to create the object on-the-fly and keep them only for as long as the code depends on that request and its result.
Hi, I am using you library, it works great when i get status code: 200. But if the server send error for some reason, then i get status code -2 or -3 and then it is not send again requests to server.
Code: