- Home /
HTTP Response Headers?
I see how to set headers for GET and POST, but how do I get the headers on the response? There's data there that I need to read.
So, how can I get the response headers returned by the server? Nothing in the WWW class, and how would it work with Webclient? (Net Framework)
Answer by Lucas Meijer 1 · Aug 01, 2010 at 10:01 PM
We added support for responseheaders to the WWW class in Unity3.
Yeah just found it thanks to C# intellisense. The responseHeaders shouldn't be a HashTable because eg. "Set-Cookie:" can be included multiple times in one response header. The HashTable can only contain one "Set-Cookie:". Would be nice to have a fix for this, anytime ;)
How does this work? The documentation has no information on this.
It's just a Hashtable. Just query the header you want to read:
// C#
string cookie = www.responseHeaders["Set-Cookie"];
// JS
var cookie = www.responseHeaders["Set-Cookie"];
Why can't ResponseHeaders be read before the requested file is completely downloaded? It would be quite nice if I could show players how many $$anonymous$$B are left to go in their AssetBundle download while they watch a bar slide across their screens. (Also see here: http://answers.unity3d.com/questions/196661/extra-www-download-statistics.html?viewedQuestions=196657&viewedQuestions=196344 )
Answer by Simon Wittber · Jan 31, 2011 at 06:51 AM
UniWeb provides complete support for HTTP. It should support everything you need.
When making a response promoting your own product, you should really include a disclaimer
Answer by Mike 3 · Jul 22, 2010 at 12:13 AM
You can't with the default WWW implementation. You'd have to go through the .NET web client class most likely:
http://msdn.microsoft.com/en-us/library/system.net.webclient(VS.80).aspx
That is... not so good. Thanks for the response. I have no idea how to do that, so if you happen to have additional insight there, that would be helpful.
There are plenty of tutorials around, e.g. http://dotnetperls.com/webclient
Your answer
Follow this Question
Related Questions
WWW Form upload with header not working 2 Answers
Error when creating http request. GET request with custom headers is not supported. 3 Answers
Upload large files 0 Answers
GET Request Wrapper 1 Answer