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
0
Question by Michcan · Jan 15, 2016 at 09:22 AM · c#textserverphpwwwform

Writing an array to a txt document and send it to my server

Hi, im trying to write an array to a txt file (Done succesfully) and then im trying to send the text file to my server via php.

this is my current code for doing this:

 IEnumerator UploadFileCo (string uploadURL)
 {
     WWW localFile = new WWW ("file:///datacolores.txt");
     yield return localFile;
     if (!(localFile == null)) {
         Debug.Log ("Good");
     } else {
         Debug.Log ("NULL");
     }
     WWWForm postForm = new WWWForm ();
     postForm.AddBinaryData ("file", localFile.bytes, "datacolores.txt", "text/plain");
 
     WWW upload = new WWW (uploadURL, postForm);
     yield return upload;
     if (upload.error == null) {
         Debug.Log (upload.text);
         Debug.Log ("upload error null");
     } else {
         Debug.Log ("Error: " + upload.error);
         Debug.Log ("isdone: " + upload.isDone);
         Debug.Log ("bytesdownloaded " + upload.bytesDownloaded);
         Debug.Log ("progress " + upload.progress);
         Debug.Log ("url " + upload.url);
         Debug.Log ("responseheaders " + upload.responseHeaders);
         Debug.Log ("size " + upload.size);
         Debug.Log ("text " + upload.text);
         Debug.Log ("uploadprogress " + upload.uploadProgress);
 

     }
 }

 void UploadFile (string uploadURL)
 {
     StartCoroutine (UploadFileCo (uploadURL));
 }

} and: UploadFile ("http://myserver.com/upload.php");

i get this error: 400 Bad Request

Can anyone point me to the right direction?

Comment
Add comment · Show 11
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 Hellium · Jan 15, 2016 at 09:25 AM -1
Share

This is not a question related to Unity, but with C#. Question rejected

avatar image Michcan · Jan 15, 2016 at 04:08 PM 0
Share

c# is the program$$anonymous$$g base of unity! are you mentaly disabled or how can you say c# is not related to unity?

avatar image Hellium Michcan · Jan 15, 2016 at 07:53 PM 0
Share

Unity answers is a Question / Answer site about Unity. If you want help about a question which is only C# related, ask on a C# Question / Answer site

$$anonymous$$oderators guideline

Reasons for a question to get rejected in the mod queue

  • Non-Unity question: we want to strictly keep Unity Answers for Unity-related content.

avatar image Michcan Hellium · Jan 18, 2016 at 12:50 AM 0
Share

yes, but the WWW class is a class from UnityEngine right? and im having trouble with that class as you can see in the description of my question

Show more comments
avatar image Dave29483 · Jan 19, 2016 at 08:34 AM 0
Share

Have you checked that localFile.bytes is not null?

Also have you tested upload.php outside of unity as a sanity check?

avatar image Michcan Dave29483 · Jan 25, 2016 at 12:58 AM 0
Share

Yes i doubled checked and localFile.bytes is not null

and yes i tested different upload.php files.

if it helps my upload.text debug:

text

Bad Request

Your browser sent a request that this server could not understand.

Additionally, a 400 Bad Request error was encountered while trying to use an ErrorDocument to handle the request.

UnityEngine.Debug:Log(Object) c__Iterator0:$$anonymous$$oveNext() (at Assets/HACERCUADROS.cs:140)

avatar image Michcan · Jan 27, 2016 at 08:55 AM 0
Share

any one??

avatar image Bunny83 · Jan 28, 2016 at 11:48 AM 0
Share

You need to get a better understanding of how the htt(p) protocol works. If Unity gets a 400 Bad Request it's either a problem on your server or you send the wrong request that your server doesn't understand. In both cases it's related to your server / server configuration and not the WWW class. Are you sure:

  • your server looks for an URL encoded field called "file"?

  • it expects a post request for the upload.

  • you use the correct protocol in your url? Some servers are configured to only accept "https" requests.

  • if it's a freehoster, make sure the webserver actually allows uploads at all.

  • serverside script is able to process the file correctly? For example if it is supposed to store that file on the server with the file name "datacolores.txt", are you sure the file doesn't exist yet?

You keep bumping your question without adding anything useful. We can't tell you what's wrong with your setup since the problem is on the server. If you get an actual response from the server that means the connection was successful and the server received your request but was unable to handle it, for whatever reason.

No one will be able to "answer" this question since it's just lacking information. From what we see you're not doing anything wrong in general. However as said it depend on your server side script and server configuration. $$anonymous$$aybe it expects some kind of security cookie?

avatar image Michcan Bunny83 · Jan 29, 2016 at 07:36 PM 0
Share

than you very much for your reply,

as i said before i tested a lot of php files and im sure the php files are correct, im NOT using a freehoster, and im sure there is no datacoleres.txt file in my server. the onlything im not sure is about the correct protocol, you say some servers are configured to only accept https requests, do you have any idea how can i check this? and how can i help for giving more information, what do you need? Sorry for my horrible english and again thankyou very much for your reply!! Hope you can still help me.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by nre3d · Feb 12, 2018 at 09:33 PM

This example worked fine for me. https://forum.unity.com/threads/need-help-with-scripting-php-for-uploading-txt-files-to-http-server.466039/

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

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

6 People are following this question.

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

Related Questions

How would I use a server to constantly check time to prevent cheating? (Energy System) 4 Answers

Help with saving XML files with PHP to a server 0 Answers

Retrieving online highscores (following a guide) 1 Answer

Send an integer array through WWWForm 1 Answer

WWW form isn't working in Build 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