Hello,
we have created a unity webgl application that needs to download files with custom http headers and are located on a different server.
We have configured the CORS and with the 2018.4.16f1 version of unity the mechanism worked correctly, with the 2019.3.5f1 version it only works first time, after which the headers dictionary (GetResponseHeaders) is empty!
IEnumerator GetRequest(string uri)
{
using (UnityWebRequest webRequest = UnityWebRequest.Get(uri))
{
yield return webRequest.SendWebRequest();
string[] pages = uri.Split('/');
int page = pages.Length - 1;
if (webRequest.isNetworkError)
{
Debug.Log(pages[page] + ": Error: " + webRequest.error);
}
else
{
byte[] bs = webRequest.downloadHandler.data;
Dictionary<string,string> hdrs = webRequest.GetResponseHeaders();
string s = "";
foreach (KeyValuePair<string,string> hdr in hdrs) {
s += hdr.Key + " => " + hdr.Value + "\n";
}
Debug.Log(
"Uri: " + uri + "\nHeaders\n" + s + "Bytes: " + bs.Length +
"\nCONTENT-TYPE: " + webRequest.GetResponseHeader("CONTENT-TYPE")
);
}
}
}
Note: We noticed from the chrome developer panel that the first call is a GET the second a HEAD
Has anyone had the same problem?
Are different settings required for CORS?