Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Wollan · Feb 11, 2016 at 09:34 PM · weburlhttphttpwebrequest

WWW does not show Location in header response (302/Redirect)

There are some nice guides out there on how to manually handle redirects (HTTP code 302) using the Unity WWW class. See:

http://answers.unity3d.com/questions/143863/doesnt-www-like-http-302-redirect.html

http://forum.unity3d.com/threads/issues-with-wwwform-necessary-data-rewind-wasnt-possible.64152/

There's one thing though... when scanning the response headers for a 'Location' header it doesn't show?

Using Fiddler (or WireShark) I can see that the response does indeed have this header: alt text

..so using this piece of code in Unity I'm expecting to have it listed: alt text

But that is not the case. Here's the Unity console log (five headers found):

  • STATUS HTTP/1.1 302 Found

  • X-POWERED-BY Someone

  • CACHE-CONTROL private, no-cache, no-store, must-revalidate

  • EXPIRES -1

  • PRAGMA no-cache

Anyone have an idea?

fiddler.jpg (56.1 kB)
fiddler2.jpg (15.7 kB)
Comment
Add comment · Show 3
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 Wollan · Feb 12, 2016 at 09:58 AM 0
Share

Seems like someone else has encountered this wall as well: http://answers.unity3d.com/questions/974722/what-is-a-good-cross-platform-alternative-to-www.html

avatar image Wollan · Feb 12, 2016 at 04:00 PM 0
Share

Attempted adding a custom header like 'redirectURL' on server response that would reach the scan before getting cut off by WWW-bug. It is successful but problem is that I'm dependent on setting a cookie and the SET-COO$$anonymous$$IE header is cut off like all the other headers following 'Location'. So now I'm in the works of creating a custom-header for that data as well (getting said data from server pre-response is proving a challenge though).

avatar image Wollan · Feb 12, 2016 at 04:42 PM 0
Share

Used reflection on the www object and then calling the protected property 'responseHeadersString' and it makes it clear that the headers are missing on the C# layer (as detailed in the question-link within my first comment). Reflection-tip was found here: https://feedback.unity3d.com/suggestions/wwwresponseheaders-dont-follo

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by Wollan · Feb 14, 2016 at 02:03 AM

Well the final solution was to 'hack' the server-side code.

I am now reshuffling my HTTP headers so 'set-cookie' comes before 'Location' (which is where the rest of the HTTP header fields gets cut off due to the underlying Unity WWW bug).

I am also adding a custom header called 'redirectURL' that has the same value as 'Location' would have.

Within Unity scripts I'm handling the redirect and cookie management manually.

EDIT: Actually since you can't set headers with a Unity WWW GET-request (sigh) meaning I can't add cookie I ended up adding another custom header. Server now also sends 'sessionID' which I can pass back from Unity as a URL query parameter.

2ND EDIT: Deployed on Android (outside of the Editor) the behavior changes drastically. Likely it's using a different library than CURL. But to summarize: It redirects but it doesn't apply cookie or give control before re-directing (so you can't pass sessionID etc). The solution altogether is to have an alternative login function server-side purely for Unity that doesn't even attempt to redirect. Handle every step of the way manually.

Comment
Add comment · Show 7 · Share
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 mitchmeyer1 · Feb 07, 2017 at 10:35 PM 0
Share

@Wollan How did you figure out which header was causing the error? Im getting the same bug you are but idk where to start. You had more than Location taken off your response. How did you know what order to put them in?

avatar image Wollan mitchmeyer1 · Feb 07, 2017 at 10:43 PM 0
Share

In the original Question you can see a screenshot from fiddler showing the full response as it exits server-side. If you compare it to the Unity log detailed just below that image you will see the contents cuts off right before the 'Location' header is supposed to show. I just ended up making sure to put in all the important stuff before that 'Location' header hit (I also tried deleting the 'Location' header but there was complications with the lib I was using server-side).

A snippet from my server-side code:

//first I apply my custom headers which will come first in the response (above 'Location')

response.set('sessionID', session.id); //initial request from android had login details, my server-side code generates a valid session object.

response.set('redirectURL', '/myserverapuiurl/user'); //I manually redirect to this url within Android after with the sessionID in hand.

response.send('Logged in'); //this is actually where the full response is both built and sent within my server code

avatar image mitchmeyer1 Wollan · Feb 07, 2017 at 10:49 PM 0
Share

Hmm weird. Here are my responses in my unity app.

content-type: [application/json; charset=utf8, cache-control: "max-age: 0, must-revalidate]

And here are the response header keys in Charlesproxy. Doesn't seem to be an order thing for me HTTP/1.1 200 O$$anonymous$$\n

X-Frame-Options: ALLOWALL

X-XSS-Protection: 1; mode=block

X-Content-Type-Options: nosniff

Access-Control-Allow-Origin: null

Access-Control-Request-$$anonymous$$ethod: *

Content-Type: application/json; charset=utf-8

Test-Header3: YES

Access-Control-Allow-$$anonymous$$ethods: GET, HEAD, POST, PUT, PATCH, $$anonymous$$ETE, OPTIONS

Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept, Authorization

access-token: dH3fzaZCaiYbwz26Td5CtA

token-type: Bearer

client: FUzJ1Auzpl8maxfePxIa5Q

expiry: 1487715230

uid: fge2@bluestreakmath.com

ETag: W/"90b9df6359868e46dffd9fb5e01922f9"

Cache-Control: max-age=0, private, must-revalidate

X-Request-Id: 42722eba-09f1-401e-9b79-7e34380cb596

X-Runtime: 0.331878

Access-Control-$$anonymous$$ax-Age: 1728000

Access-Control-Allow-Credentials: true

Vary: Origin

Transfer-Encoding: chunked

Proxy-Connection: $$anonymous$$eep-alive

Are you quite confident in your case it had directly to do with order?

Show more comments
avatar image rmassanet · Jun 19, 2017 at 06:53 AM 0
Share

Is there an issue tracker for that "underlying Unity WWW bug" you mentioned?

I have searched and the closest I could find was this:

https://issuetracker.unity3d.com/issues/www-ios-android-status-and-other-keys-missing-from-www-dot-responseheaders-on-mobile

Which is flagged as "Not reproducible".

I do need to read the Location for deep linking purposes, but I am unable to get it from the HTTP response. It is just not there.

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

UriFormatException: Invalid URI: Invalid port number for VirtualBox server using IPv6 Address 1 Answer

Can't fetch site as string. Unitywebrequest 1 Answer

Failed to connect to localhost port 80: Connection refused 2 Answers

VideoPlayer+UnityWebRequest 1 Answer

communication ovedr http 0 Answers


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