• 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 Michcan · Apr 02, 2016 at 10:34 PM · arraywwwphpwwwformbyte

wwwform send an array the right way!

Hello, i have been struggling with t$$anonymous$$s part of my code for at least a week, but i can't find any information online for doing t$$anonymous$$s,

the only t$$anonymous$$ng i want to do is to send an array to a php script in my server, t$$anonymous$$s can be done very easily in a lot of ways, i successfully done t$$anonymous$$s with $_GET, (www), but my array is way to big, so i get an error. the other method is to post it via POST (wwwForm), but if i do it in .addField() it also gets an error because my array is to big.

Finally my last option is to send it via addBinaryData right? well i have a lot of headaches trying to do t$$anonymous$$s because i ALLWAYS receive the error : 400 BAD REQUEST.

My code goes like t$$anonymous$$s:

 //I use a simple method to convert my multidimensional array to byte[]

 public byte[] Encode (int[,] input)
 {
     int d0 = input.GetLength (0), d1 = input.GetLength (1);
     byte[] raw = new byte[((d0 * d1) + 2) * 4];
     Buffer.BlockCopy (BitConverter.GetBytes (d0), 0, raw, 0, 4);
     Buffer.BlockCopy (BitConverter.GetBytes (d1), 0, raw, 4, 4);
     int offset = 8;
     for (int i0 = 0; i0 < d0; i0++)
         for (int i1 = 0; i1 < d1; i1++) {
             Buffer.BlockCopy (BitConverter.GetBytes (input [i0, i1]), 0,
                 raw, offset, 4);
             offset += 4;
         }
     return raw;
 }

//Here i convert my multidimensional array to byte[]

  byte[] sendingByte = Encode(myArray);

//Create the WWWForm

     WWWForm form = new WWWForm ();

//Add the byte[] for sending ( t$$anonymous$$s is where i t$$anonymous$$ng i made the errors, please help)

     form.AddBinaryData ("file", sendingByte, "file.tmp", "application/octet-stream");
 

     WWW w = new WWW (www.myserver.com/post.php, form);

     yield return w;

     Debug.Log (w.text);

     if (w.error != null) {
         Debug.LogError ( w.error);

     } else {
         Debug.Log ("Done");
     }

 }


Ok the t$$anonymous$$ng is i only want to receive the array, convert it again to an array of int , so in my php script i can INSERT those values to a mysql database, is t$$anonymous$$s the right way to do it? is there another option? Thank you !

Comment
Add comment · Show 1
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 Copyrightbraker · Aug 31, 2016 at 11:32 PM 0
Share

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Disable execute/write permissions on PHP files while maintaining the ability to execute them from Unity? 1 Answer

After updating to v2017.1, a www call returns "406 not acceptable" 2 Answers

WWWForm problem 1 Answer

Array Dump to String for Send via WWW 1 Answer

PHP POST through $_REQUEST with WEBBUILD 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