UnityWebRequest with "text/event-stream" header doesn't work in webgl build
Hi!
I am trying to implement a request to firebase, which follows server side events protocol. It looks like this:
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class Test : MonoBehaviour
{
public IEnumerator TestCoroutine()
{
string databaseSecret = "DATABASE_SECRET";
string firebaseHost = "https://your-firebase-project.firebaseio.com";
UnityWebRequest req = UnityWebRequest.Get(firebaseHost + "/.json?auth=" + databaseSecret);
req.SetRequestHeader("Accept", "text/event-stream");
var response = req.SendWebRequest();
while (!req.downloadHandler.isDone)
{
Debug.Log("Text downloaded: " + req.downloadHandler.text);
yield return new WaitForSeconds(1);
}
}
// Use this for initialization
void Start()
{
StartCoroutine(TestCoroutine());
}
}
It works fine in editor, but no data is received in webgl build. With webgl build I can see in browser dev tools that the request is made, and that it continues running, so req.downloadHandler.isDone is false, however both req.downloadHandler.text and req.downloadHandler.data are always empty. I tried using wireshark to see if any data is passed and I observed that there are new chunks of data when the server side event is triggered by me, using another device, but it's hard to tell what this data represents - its not readable.
I wanted to know if I am doing something wrong, of it is a bug or if it is a limitation of webgl. I would appreciate suggestions on workaround. Thanks!
Answer by ferretnt · Aug 16, 2019 at 05:56 PM
Did you ever get this to work? Like everyone else asking this question, I'd love to have firebase RTDB streaming data working in Unity WebGL builds.
Your answer
![](https://koobas.hobune.stream/wayback/20220612180042im_/https://answers.unity.com/themes/thub/images/avi.jpg)