UnityWebRequest, get XML file from URL

Hello,

please, is here somebody, who has expirience with WebGL and UnityWebRequest. I need get file from url. This file is in XML format and need use it in my project, for deserialization.

    IEnumerator GetFile()
    {
        using (UnityWebRequest request = UnityWebRequest.Get("http://test.cc/Test/_TestSnapshot.xml"))
        {
            yield return request.SendWebRequest();

            if (request.isNetworkError) // Error
            {
                Debug.Log(request.error);
            }
            else // Success
            {
                snapshot = request.downloadHandler.text;
            }
        }
    }

    // Start is called before the first frame update
    private void Start()
    {
        StartCoroutine(GetText());
    }

But when I get this file: Compiled program, give in last chrome this error message:
Data at the root level is invalid. Line 1, position 1, when writing.

Thanks.

HD

Solved.

1 Like

And how? I have the same problem right now.

This is a spectacularly unhelpful post. If you solved the problem, answer your own question so others can find the answer as well.

Hey, How did you solved this problem ?? experiencing the issue…

Please help me into this matter ??

That error seems like invalid XML data, print it out, check with XML validator.

other possible common error in browser is: (see browser Console window, F12)
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at … (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).