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
1
Question by Flynn · Aug 02, 2010 at 03:27 AM · wwwformcookies

Present cookie data in WWWForm?

Hi again! I've been wondering, and it's not that important, but is it possible to actually send cookie data into a WWWForm? For example, I could somehow set "thiscookie" to "isyummy", send that to the WWWForm, and have any PHP cookie requests for "thiscookie" return "isyummy"?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by qJake · Aug 02, 2010 at 04:48 AM

No, but you can send URL parameters via GET/POST that tell PHP to set cookies for you, and then you can retrieve those cookie values from PHP. That, or you could write a JavaScript (web-javascript, not UnityScript, they're different) to get and set cookie values for you, and then you could call those from within the game using the WWW class. Unity can't directly get or set cookie data, though, no.

Comment
Add comment · Show 2 · 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 Flynn · Aug 02, 2010 at 05:43 PM 0
Share

Thanks for the info! I can call JS into WWW instances - As in run JS on the webpage that I'm loading? Or does this only work within the webpage that a web player is in?

avatar image qJake · Aug 02, 2010 at 06:56 PM 0
Share

You can only run JavaScript that the Unity webplayer is in, which is the currently loaded page... this is true for all webpages.

avatar image
1

Answer by Bunny83 · Jan 23, 2011 at 12:14 AM

Actually you can. Just setup your custom headers like in this example: WWWForm Headers You need to add the "Cookie" header. (HTTP Headers) That should do the job (not tested). There could be a difference between Web and Standalone.

Comment
Add comment · Show 3 · 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 Fattie · Jun 20, 2013 at 04:28 PM 0
Share

the annoying problem is, you can't do this

     WWWForm myform = new WWWForm();
     myform.AddBinaryData("abc", bytes );
     
     Hashtable jsonHeaders = new Hashtable();
     jsonHeaders.Add( "Cookie", theCookie );
     
     WWW w = new WWW(fullURL, myform, jsonHeaders);
     yield return w;

you can't mix a WWWForm (which allows AddBinary and thence multipart), with the form of having headers on the end as the third argument.

So you can't (my final sentence was cutoff here, so sounded weird!)

avatar image Bunny83 · Jun 21, 2013 at 12:54 AM 0
Share

Umm, well, you can, but you should use myform.headers to initialize your headers variable. This property simply returns the corect content type for the given form:

 public Hashtable headers
 {
     get
     {
         Hashtable hashtable = new Hashtable();
         if (this.containsFiles)
         {
             hashtable["Content-Type"] = "multipart/form-data; boundary=\"" + Encoding.UTF8.GetString(this.boundary) + "\"";
         }
         else
         {
             hashtable["Content-Type"] = "application/x-www-form-urlencoded";
         }
         return hashtable;
     }
 }

$$anonymous$$eep in $$anonymous$$d that WWWForm is just a helper class which should simplify the creation of a valid HTTP request. You can always setup the request yourself, but you should know what you're doing ;).

avatar image Fattie · Jun 21, 2013 at 05:07 AM 0
Share

Ah - you've just made me realise of course obviously one can "change" items in the headers.

That's awesome thanks....it just didn't occur to me.

Another thing I realised which may help future readers

Like I mentioned "you can't mix a WWWForm (which allows AddBinary and thence multipart), with the form of having headers on the end as the third argument" because they don't offer that overload.

But of course there's the handy .data property on WWWForm

so that you can use yourForm.data as the middle argument to new WWW().

I believe there are three idioms possible:

     string fullURL = "http://blahblah.com/image/add";
     string cookieString = "sid=" + uid;
     
     
     //method 1
     Hashtable jsonHeaders = new Hashtable();
     jsonHeaders.Add(
       "Content-Disposition",
       "form-data; name=\"xx\"; filename=\"newim.png\"" );
     jsonHeaders.Add( "Content-Type", "image/png" );
     jsonHeaders.Add( "Cookie", cookieString );
     WWW w = new WWW( fullURL, bytes, jsonHeaders );
     yield return w;
     
     
     //method 2
     WWWForm myform = new WWWForm();
     myform.AddField("cookie", cookieString ); 
     myform.AddBinaryData("fn", bytes ); 
     WWW w = new WWW(fullURL, myform);
     yield return w;
     
     
     //method 3
     var xform = new WWWForm();
     xform.AddBinaryData("fn", bytes ); 
     var headers = xform.headers;
     var rawData = xform.data;
     headers["Cookie"] = cookieString;
     WWW w = new WWW( fullURL, rawData, headers );
     yield return w;




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

2 People are following this question.

avatar image avatar image

Related Questions

PHPSESSID with Unity 2 Answers

A login system with www and ruby on rails? 1 Answer

How to get game in Dropbox to pull data from 000WebHost? 1 Answer

Is it possible for Unity to fetch text from a Twitch.tv chatroom? If so, how? 2 Answers

Hlw guys can anybody help me with with error. this is after building with webgl and deployed it to the server. This error comes when it suppose to download a response from a different server where my database is located. 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