Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Michcan · Apr 02, 2016 at 10:34 PM · arraywwwphpwwwformbyte

wwwform send an array the right way!

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

the only thing i want to do is to send an array to a php script in my server, this can be done very easily in a lot of ways, i successfully done this 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 this because i ALLWAYS receive the error : 400 BAD REQUEST.

My code goes like this:

 //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 ( this is where i thing 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 thing 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 this 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

Did you ever find a solution?

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.

Follow this Question

Answers Answers and Comments

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Retrieving varibale values from a php script? 1 Answer

Necessary Data Rewind Wasn't Possible WWWForm Error 0 Answers

WWW Class is acting up 1 Answer

WWWForm.Addfield not able to post data to server 1 Answer

Why isn't this $_POST working properly? 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