SendRequest routine
DATA
curl TCurlHttpClass
res CURLcode
qIndex LONG, AUTO
respBuffer &IDynStr
CODE
respBuffer &= NewDynStr()
curl.Init()
curl.FreeHttpHeaders()
IF RECORDS(HttpHeaders)
LOOP qIndex = 1 TO RECORDS(HttpHeaders)
GET(HttpHeaders, qIndex)
curl.AddHttpHeader(HttpHeaders.HttpHeader)
END
res = curl.SetHttpHeaders()
END
res = curl.SetCustomRequest(Send:CustomRequest)
res = curl.SendRequest(Send:Url, Send:Total, respBuffer)
!*I think here a -max-time or -timeout or -m*
IF res = CURLE_OK
sz#=respBuffer.StrLen()
stReturn &=New STRING(sz#+1)
stReturn = respBuffer.Str()
?txtHttpResponse{PROP:Text}= clip(stReturn)
ELSIF res = -1
?txtHttpResponse{PROP:Text}=('SendRequest ROUTINE: Cannot open local file -> libcurl')
ELSE
?txtHttpResponse{PROP:Text}=('SendRequest ROUTINE: SendRequest failed: '& curl.StrError(res))
END
DISPOSE(stReturn)
DisposeDynStr(respBuffer)
DISPLAY()
Okay, apparently curl.SetOpt(CURLOPT_TIMEOUT_MS, 30000) stops waiting for the server response at the desired time.
The problem is that it’s the total service time:
Connection,
File loading,
Reading the response.
It’s not just for the response itself.
So I’m testing with this 30-second time.
There are other operators: curl.SetOpt(CURLOPT_CONNECTTIMEOUT, 10)
and curl.SetOpt(CURLOPT_SERVER_RESPONSE_TIMEOUT, 10)
I tried using them, dropping the API to see if they worked, to see if the application wouldn’t freeze waiting for the response.
But it didn’t work.
Have you tried using a standalone REST client, such as Postman, or Insomnia to check what happens when you submit your request to the server? In my experience using these tools removes a lot of the guesswork as to what should work and what doesn’t, without worrying about what might be wrong in Clarion.
Hi, thanks for the reply, but the problem is when the server or API doesn’t return data.
The curl loop freezes the system indefinitely until something returns, and sometimes we have to restart the program to stop the curl.
I’m already researching what the alternatives are.
By default, Windows sets this to 2 hours ( 7,200,000 milliseconds).
Recommended Setting: In many environments (e.g., server applications), it is recommended to reduce this to 5 minutes ( 300,000 ms) or lower to identify dead connections faster.
Obviously you could reduce your test machine to maybe 30 seconds (30,000 ms) to see if this setting is the root cause and if it is, its bought you some time until a better solution appears.
Sorry to harp on it Jorge but, have you tried using a standalone REST client, such as Postman, or Insomnia to check what happens when you submit your request to the server?
You say you get no response, if I was doing this I’d really like to know what these tools do in this situation?
You also say that the curl loop freezes the system and separately, that it crashes - are these these the same thing?
Hello..!
Yes, we’ve already checked, it doesn’t return anything, it remains unanswered, either momentarily or because the API or server crashed.
Then the waiting system freezes, that’s it.