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
1
Question by pankao · Aug 28, 2016 at 10:45 AM · networkinghttpemptyheadersresponse

UnityWebRequest all response headers are null

Hey community ♥
I am having strange issue with web request response headers - they are listed but all of them are of null value, which is deadly in my case as i obviously need to read their data in ma app.. The server response status itself is 200 though and also other additional data (json) which is part of an expected response are arriving pretty fine.

I am basically connecting to a custom Apiary api. When I test the request with same parameters in a browser it shows the headers content ok.

here is my C# code which i use to realize request from Unity (pretty stadard i think):

 protected static IEnumerator PostUnityWebRequest(string url, string data)
     {
         byte[] bodyRaw = Encoding.UTF8.GetBytes(data);
         UnityWebRequest request = new UnityWebRequest(url, UnityWebRequest.kHttpVerbPOST);
         request.uploadHandler = (UploadHandler)new UploadHandlerRaw(bodyRaw);
         request.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
         request.SetRequestHeader("Content-Type", "application/json");
         //request.useHttpContinue = false;
         //request.redirectLimit = 0;
         yield return request.Send();
         if (request.isError)
         {
             Debug.Log("request error: " + request.error);
         }
         else
         {
             Debug.Log("server response status: " + request.responseCode);
             Dictionary<string, string> responseHeaders = request.GetResponseHeaders();
             AUTHORIZED = true;
             isAuthorizing = false;
         }
     }

here is a screenshot showing the headers as they appear in the debugger: response headers in VS debugger

here is how the same response headers appear in a web interface:
response headers in web interface

As I said, the body of the response arrives ok even in my unity request, I just cannot read the values of the headers (actually some headers are all missing too in my unity request as you can see)..

I am rather a noob regarding networking unfortunatelly, so after trying with new UnityWebRequest as well as legacy www class, I got a bit lost, even tried all other http methods (just to see if it could make any difference from standard POST). I have run through many related posts out there, from which i basically learned that there are some issues with unity networking api, particulary with redirecting but that doesn't seem to be an issue in my case.. I also tried to set different values for redirect limit in my web request. Some suggest to switch to 3rd party libs or using native .net classes instead.. which i would like to avoid as it would mean to rewrite a major part of my async asset download managers etc..

So did enyone else here experience that, or does anyone have any clue what might be a possible cause? I dont know what other info could i provide to help you help me, so please let me know:)

Thanks in advance guys!

headers.png (9.3 kB)
response.png (46.4 kB)
Comment
Add comment
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

4 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by yurykorzun · Oct 13, 2017 at 02:25 PM

I have the same issue with the 5.6.3p4 patched version of Unity.

Could it be that it is related to these changes?

(none) - UnityWebRequest : Fixed early availability of status code when UnityWebRequest was still running. (none) - UnityWebRequest : Ensure that headers are available in UnityWebRequest only after all of them are received. (none) - UnityWebRequest : Fixed possible issues aborting UnityWebRequest when using a custom download handler script.

Comment
Add comment · 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
0

Answer by jantje · Nov 04, 2017 at 04:54 PM

I am seeing a similar issue in 2017.2.0f3, but slightly different. I am using UnityScript, and for me the www.responseHeaders are null, but only in the case where the body is empty. Once I add even just a single character to the body, then the www.responseHeaders are all happy. Fortunately for me, since I control the server I added a catch-all to the response handler on my server to just add a ' ' space character as the body if the body is empty.

Comment
Add comment · Show 1 · 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 RichLogan · Nov 08, 2017 at 11:24 AM 0
Share

Just to add to this for anyone looking, it seems to always reproducible when the reponse body is empty AND a download handler is attached.

In my case, I was making HEAD requests that also had a DownloadHandler attatched. To workaround the current problem, removing the DownloadHandler when you know you won't get any body should return you the headers as expected. I've filed a Bug Report will some reproductions too.

avatar image
0

Answer by pgilmorepf · Dec 22, 2017 at 06:49 PM

  • https://community.playfab.com/answers/16353/view.html

  • https://community.playfab.com/questions/15741/unity-2017-fatal-error-on-android-get-response-hea.html

  • https://community.playfab.com/questions/15458/upgrading-to-unity-2017.html

We have gotten several reports about how Android devices simply crash when trying to access the response headers. We've gotten other reports about exceptions when getting response headers, which we've worked-around with a try-catch.

Response headers are necessary to determine if the response has been encrypted. It's also a major regression from the old, functional WWW mechanism.

Comment
Add comment · 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
0

Answer by andrew-fray · Apr 19, 2018 at 06:47 PM

This is fixed in 2017.2.1

Comment
Add comment · 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

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

8 People are following this question.

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

Related Questions

Empty response headers with WWW + Firefox 0 Answers

Serious Bug UnityWebRequest.SetRequestHeader is not working in non development mode on Android 1 Answer

working with cookies On Android Devices 1 Answer

why does UnityWebRequest want Dispose() ? 1 Answer

Adding Custom Headers/Cookies to the UnityWebRequest.Post 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