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 SolidSnake · Dec 06, 2011 at 01:22 PM · wwwapihttp

WWW class and HTTP Headers

Hi All,

Does anyone know if the WWW API will allow setting the HTTP headers for GET requests?

Thanks

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

3 Replies

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

Answer by Bunny83 · Dec 06, 2011 at 01:57 PM

No, it doesn't. If you read the docs on WWW you may have noticed that only the constructor with a single URL string will produce a GET request. All other versions use POST.

edit

I just had a look into the UnityEnigne.dll and it seems the single string argument constructor just uses WWW(url,null,null). So basically all use the same constructor. Now it depends on how Unity determines if it should send a POST or GET. Maybe they just look for the postData != null. So if you pass null it might send the request via GET. You have to try it yourself.

Comment
Add comment · Show 6 · 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 SolidSnake · Dec 06, 2011 at 02:28 PM 0
Share

thanks I will give it a try

avatar image Bunny83 · Dec 06, 2011 at 02:32 PM 0
Share

If you have new information, feel free to add an answer yourself that clears things up for others.

avatar image SolidSnake · Dec 06, 2011 at 02:38 PM 0
Share

it didnt work. once i had a header value it changed to post. but thanks

avatar image Bunny83 · Dec 06, 2011 at 03:01 PM 0
Share

That's a pity. Well, the only other way would be to use .NET / $$anonymous$$ono functions for the request. If you build for the webplayer, make sure the class / function is available and you provide a crossdomain-policy file.

avatar image aditya007 · Nov 17, 2016 at 08:54 AM 0
Share

I just had a look into the UnityEnigne.dll

@Bunny83, how did you looked inside it?

avatar image Bunny83 aditya007 · Nov 17, 2016 at 11:47 PM 1
Share

Well, by using any .NET / $$anonymous$$ono assembly browser / decompiler. Personally i use ILSpy. It's free, open source and can decompile to C#, VB.NET or just IL code.

avatar image
4

Answer by delsolu · Sep 19, 2013 at 06:22 AM

The key is leaving "postData" parameter to null. From Unity3D WWW reference

The WWW class will use GET by default and POST if you supply a postData parameter.

So this one works for me:

 var form = new WWWForm();
 var headers = new Hashtable();
 headers.Add("Header_key", "Header_val");
 www = new WWW("http://localhost/getpostheaders", null, headers);
 yield return www;
 Debug.Log("2. " + www.text);
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
1

Answer by Simon Wittber · Feb 08, 2012 at 03:20 AM

The WWW class does not allow this. UniWeb does.

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 oddurmagg · Sep 04, 2013 at 05:09 PM 0
Share

Using UniWeb comes with all sorts of other problems, such as having to setup a SocketPolicy listener on the server which requires another open port on the backend.

If you have control over your backend, I'd recommend changing it to support the given http endpoint using POST as well. It sucks and breaks the Restfulness if you'r backend api.

Unity not supporting custom headers for GETs really sucks.

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

7 People are following this question.

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

Related Questions

WWW class does not work 1 Answer

Unable to call external API (IBM Watson) via HTTP request? 1 Answer

Calling API via proxy 0 Answers

Is pulling and parsing XML data from 3rd party API call possible? 1 Answer

http request over an https webgl 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