Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by nesis · May 26, 2015 at 05:58 PM · webrequesthttpwebrequesthttps

What is a good cross-platform alternative to WWW?

I've been integrating the Firebase 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 = "<some firebase URI>";
 byte[] postData = new byte[]{0}; //some non-null value needed to force WWW to use POST
 Dictionary<string,string> headers = new Dictionary<string,string>();
 //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, 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.

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...

Comment
Add comment · Show 7
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image spiceboy9994 · May 27, 2015 at 05:32 PM 0
Share

Have you tried to parse the response headers of the WWW response?

 request.responseHeaders["STATUS"]

That should give you the information of a redirect, and then you could apply your logic to that specific response.

Here's the definition for the property:

http://docs.unity3d.com/ScriptReference/WWW-responseHeaders.html

Regards

avatar image nesis · May 27, 2015 at 11:36 PM 0
Share

Hey, thanks for trying to help :)

I must have been unclear in my original post - I have verified that the response header isn't available by dumping all keys and values from responseHeaders and inspecting their values both by eye and in code. I am doing this irrespective of the contents / null state of the error property.

avatar image nesis · May 28, 2015 at 02:47 PM 0
Share

Also, when dumping all responseHeaders, the response header "STATUS" does indicate a 307 Temporary Redirect. But no location is defined in any other header, though there should be a redirect URL available in the "LOCATION" header.

avatar image spiceboy9994 · May 28, 2015 at 03:06 PM 0
Share

Do you need the redirect url from the response? or is that something that you want to manually specify?. If your scenario is the second one, here's an idea just to check if this applies.

  1. You execute a http request using WWW

  2. As part of your post request, you send a RedirectUrl parameter, with the url for the manual redirection

  3. The Request responds with an Status of 307 Temporary Redirect

  4. Your code "catches" this logic flow, and executes another WWW request to your RedirectUrl original parameter.

It's just an idea :$

If you want to perform a redirect with the "Location" header from the WWW response, I think the location is not available on this result (just for the 301, 302 status codes). I did a bit of research and with that status code and that result asumes that the server do not need to redirect, so that's the reason that no Location url is provided. I did a bit more research (I'm very curious about web requests / responses :D) and, with other languages and there's a post that suggests to respost exactly the same (params and method) when receiving a 307 status code.

http://programmers.stackexchange.com/questions/99894/why-doesnt-http-have-post-redirect

Give it a try

avatar image spiceboy9994 · May 28, 2015 at 03:14 PM 0
Share

Here's another very well explained (and very loooong post) about the redirect status http://sebastians-pamphlets.com/the-anatomy-of-http-redirects-301-302-307/

Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

21 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Capturing and Tracing All HTTP Requests in Unity project 0 Answers

HttpWebRequest and HTTPS on iOS 0 Answers

About Implemented host name resolution with IPv6 in Unity 4.6.9 release-notes. 0 Answers

Using HttpWebRequest asynchronously with HTTPS 0 Answers

WebRequest.BeginGetRequestStream fails on iOS using IPv6 DNS64/NAT64 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges