Libcurl get params in utf-8?

Hello everyone !!

I am with libcurl doing get to an API and I can pass a filter as a parameter as follows

where={ “nsacrux”: 20}

leaving the url as follows

NNN.com{ “nsacrux”: 20}

the issue that gives me error 400.

Playing with the VCode Thunder Client extension (it’s where I test the API call) it generates the curl and the where does it as follows:

where=%7B%22nsacrux%22%3A%2020%7D

and it stays working if I call with libcurl NNN.com

how could i solve it?

thank you so much

What does utf-8 have to do with your question?

Hi Mike, it’s nice chatting with you.

When I convert the GET call to curl, the parameter is passed to utf-8

I have tried it with libcurl without converting the parameter to utf-8 and it gives error 400. Maybe it is a mistake or a misinterpretation on my part

That’s not what utf-8 is. This is just encoding the non-URI-friendly characters as hex. The % means that the following 2 characters are hex.

If you can’t find a way to convert that, I have a method here: AmbleScrayLite/Clarion/JS_HexTools.clw at 60a07f7ba808baef995c4a93f3c2763b2f70b6b9 · jslarve/AmbleScrayLite · GitHub

1 Like

that example misses parts of the url after the .com, on the image it can be seen rux?where= , can you confirm the url you tested was complete?

Hi Carlos,

It is not utf-8, it is url encoding. You can use TCurlUrlApiClass or printf to encode:

TCurlUrlApiClass approach:

uapi                          TCurlUrlApiClass
  CODE
  host = 'http://server.com'
  params = 'where={{ “nsacrux”: 20}'
  uapi.Init()
  uapi.SetPart(CURLUPART_URL, host)
  uapi.SetPart(CURLUPART_QUERY, params, CURLU_URLENCODE)
  uapi.GetPart(CURLUPART_URL, url)
  rc = curl.SendRequest(url,...)

printf approach:

  host = 'http://server.com'
  params = 'where={{ “nsacrux”: 20}'
  url = printf('%s?%u', host, params)
  rc = curl.SendRequest(url,...)
3 Likes

Oh! my God!! Sorry for the misconception on my part.

I have learned something new today.

Thank you very much to all !!