I've been integrating the [Firebase API](https://www.firebase.com/docs/web/api/) in Unity for a few days now. The WWW class is a bit tricky to wrangle, but I got it working as intended with Firebase's basic RESTful API. To do this, I force a WWW object to operate on POST as such:
string someUrl = "";
byte[] postData = new byte[]{0}; //some non-null value needed to force WWW to use POST
Dictionary headers = new Dictionary();
//as per Firebase's API docs, specify HTTP method in this header
headers.Add("x-http-method-override","GET");
WWW webRequest = new WWW(someUrl, postData, headers);
However, in attempting to use this same strategy for querying [Firebase's Streaming API](https://www.firebase.com/docs/rest/api/#section-streaming), the WWW object I construct isn't handling "307 Temporary Redirect" response codes as needed. An error is silently caught inside webRequest and webRequest's error property is set to contain it. Although webRequest's status header indicates a "307 Temporary Redirect" response code, there is no "Location" header to redirect to. This was checked by dumping the keys and values in the webRequest.responseHeaders property.
The error is from its underlying cURL calls, saying "necessary data rewind wasn't possible". For reference, the cURL line with the error (assuming Unity3D uses the latest cURL on github): [https://github.com/bagder/curl/blob/b0143a2a33f0e577b1c2c9a407ac081418b5ea6b/lib/transfer.c#L299](https://github.com/bagder/curl/blob/b0143a2a33f0e577b1c2c9a407ac081418b5ea6b/lib/transfer.c#L299).
Since no Location header is given for the redirect request, I cannot attempt to perform a redirect manually. There appears to be no way to force the WWW class to expose all headers it was sent, or to ensure it doesn't attempt an automatic redirect.
So, knowing that is an issue preventing use of the WWW class from using Firebase's Streaming API...
**Are there any cross-platform alternatives for making HTTP requests, ideally built in to Unity for a better guarantee of ongoing support?**
I see there's System.Net, but Googling suggests its cross-platform support is sketchy, and that it's mainly intended for Windows PCs.
Any suggestions / recommendations would be very much welcome! :) I think I've squeezed all I can out of the WWW class...
↧