2

My site communicates with a remote API to synchronize databases. The data I receive is in XML and 999 out of 1000 times this is proper XML which I can directly parse using simplexml_load_string.

Yet 1 out of 1000 times I get incorrectly encoded XML as shown in the attached image below.

I must somehow parse this gibberish, because trying to GET the same record will again give the same result.

If you have a suggestion on how to convert this, please let me know. I have tried the following functions but I am not a decoding expert so there were just shots in the dark:

  • gzdeflate($result)
  • utf8_decode($result)
  • iconv("UTF-8", "UTF-8//IGNORE", $result)
  • base64_decode($result)
  • iconv(mb_detect_encoding($result, mb_detect_order(), true), "UTF-8", $result)

    wrong encoding

Hacktisch
  • 1,392
  • 15
  • 33

1 Answers1

1

BareNakedCoder suggested looking at the response headers and the answer was there: apparently the authentication tokens for this api expire very fast, even during the execution of my script. See attached image for the headers. So the solution is to re-authenticate every time when this happens.

Pity the api doesn't just say this in the regular XML output.

This happens in the api of Exact Online (accountancy software), so I will add that as a keyword to the original question.

headers

Community
  • 1
  • 1
Hacktisch
  • 1,392
  • 15
  • 33