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
0
Question by Thet Naing Swe · May 10, 2011 at 10:51 AM · getheaders

Adding headers to Get request///

How can I add header information to make the GET request from Unity www class. I use headers in POST method as below and it works.. WWWForm form = new WWWForm(); form.AddField("email", email); form.AddField("password", password); byte[] rawData = form.data;

Hashtable headers = form.headers; headers["Game-Key"] = "549efcadf98"; headers["Game-Secret"] = "b6dc5%aa7b%a1ff#3696$";

 WWW www = new WWW(url, rawData, headers);

Now, I am trying to get the gamer information with GET request and I've no idea of how to make it... I tried the same as before and WWWForm is for POST only.

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
7

Answer by delsolu · Sep 19, 2013 at 06:21 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 Numid · Aug 10, 2012 at 11:53 AM

Here's a hacky suggestion.

C# code executed from the editor

 string url = "http://mydomain.com/myphpscript.php?param1=value1&param2=value2";
 Hashtable headers = new Hashtable();
 headers.Add("Cookie", "PHPSESSID=qo62537o8djtojba7f05pu8u83");
 WWW www = new WWW(url, new byte[] {(byte) 0}, headers);
 yield return www;
 Debug.Log(www.text);

PHP back-end script

 <?php
 
 print_r(getallheaders());
 print_r($_GET);
 
 ?>

Output in console

 Array
 (
   [User-Agent] => UnityPlayer/3.5.2f2 (http://unity3d.com)
   [Host] => mydomain.com
   [Accept] => */*
   [Content-Length] => 1
   [Cookie] => PHPSESSID=qo62537o8djtojba7f05pu8u83
   [Content-Type] => application/x-www-form-urlencoded
 )
 Array
 (
   [param1] => value1
   [param2] => value2
 )

The request method is POST, but PHP seems to retrieve the GET parameters anyway.

This may depend on your server-side setting (language and configuration). However this is worth trying.

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 siddharth3322 · Jun 19, 2016 at 05:02 PM 0
Share

In WWW constructor, we can't able to pass null otherwise it's firing 404 Not Found error always. By passing 0 byte data, problem get resolved. Really thanks for this reply.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

HTTP Response Headers? 3 Answers

NullReferenceException error, GameObject.Find. 1 Answer

how to get the child of an instanteated object 2 Answers

Object Reference Required To Access A Non-Static Field 1 Answer

Get prefab through script 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