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 gigos22 · Jan 18, 2021 at 08:40 AM · webglwebrequest

Error: HTTP/1.1 405 Method Not Allowed

When I try to use UnityWebRequest.Put() I get the error aforementioned.


I am hosting my game on HostGator.

I've asked their tech support but they have no idea and they say I should consult with a Web Developer.

So instead I'm consulting with this amazing community.


I want to state that my initial plan was to use UnityWebRequest.Post(), but I can't find a way to send byte[] through this function. It is only possible to do so with the UnityWebRequest.Put() function.


This is the part of my code where I try to upload a new binary file:

 public static PlayerData[] OldPlayersData;
 
     public static IEnumerator SavePlayer(PlayerData player)
     {
         byte[] finalDataToSend;
 
         PlayerData[] newData = new PlayerData[] { player };
 
         newData = newData.Concat(OldPlayersData);
 
         BinaryFormatter bf = new BinaryFormatter();
 
         using (MemoryStream ms = new MemoryStream())
         {
             bf.Serialize(ms, newData);
             finalDataToSend = ms.ToArray();
         }
 
         UnityWebRequest www = UnityWebRequest.Put(putPlayersURL, finalDataToSend);
         yield return www.SendWebRequest();
 
         if (www.isNetworkError || www.isHttpError)
         {
             Debug.LogError(www.error);
         }
         else
         {
             Debug.Log("done");
         }
 
     }


Bottom line, my questions are:

  1. Is there a way to make this method allowed? If not, is there a work-around?

  2. Is there really no way to send byte[] data through UWR.Post()?

  3. Please help my solve this in any other way. This is crucial to me.

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Bunny83 · Jan 18, 2021 at 09:27 AM

This purely depends on the server you're communicating with. The 405 reponse code is generated by the server. It tells you that the used method is not allowed for the resource in your URL. This is usually the result of not allowing any of the extra HTTP verbs like PUT or DELETE. See this SO question. If the support of your hoster doesn't know what you're talking about, they should change business -.- Though as you can read in the answer to the SO question, free / shared hoster usually don't have those methods enabled.


So your options are:

  • ask your current hoster if they can enable the extra verbs like PUT / DELETE / (whatever you may also need)

  • change to a hoster that specifically supports the use of those request methods.

  • change your API (if possible) so that it uses a supported verb. Usually POST should work on all free hoster.

  • finally you could host your own server where you have full control over the server and its settings.


There are not really alternatives. I don't quite understand your comment that POST does not support sending data. Of course it does. Though you have to use an UploadHandlerRaw because Unity did not provide an overload of the Post method to initiate a post request with a byte array. Something like this should work

 UnityWebRequest www = new UnityWebRequest( YourURL , UnityWebRequest.kHttpVerbPOST );
 UploadHandlerRaw MyUploadHandler = new UploadHandlerRaw( finalDataToSend );
 MyUploadHandler.contentType= "application/octet-stream";
 www.uploadHandler= MyUploadHandler;
 yield return www.SendWebRequest();

Finally I should add that you should not use the BinaryFormatter, especially when saving / loading data over the internet. The BinaryFormatter is not secure. So using it will make your application vulnerable to all sorts of security issues. Please read the security guide that Microsoft has released. You should use more robust formats like json. If you really want a binary format you could either compress the json string or roll your own binary format using BinaryWriter / BinaryReader.

Comment
Add comment · Show 7 · 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 gigos22 · Jan 18, 2021 at 10:22 AM 0
Share

First of all let me say that you've made me a bit smarter with your respond.

Now, I tried the piece of code that you suggested, and although it does seem to work (there is no error to be printed), it is actually not working, because when I get the data again, it is the same.. It did not change.

So I don't know what it did with what I sent, but it surely didn't replaced my file.

$$anonymous$$aybe I'm doing something wrong?

avatar image Bunny83 gigos22 · Jan 18, 2021 at 11:34 AM 0
Share

Well, what are you doing on your serverside? HTTP in general is a read only, request based protocol. It's not a file system. The new verbs PUT and $$anonymous$$ETE are kind of an extension to give almost file system like access to resources. However the handling of such requests is generally controlled / consumed by server side scripts which perform the necessary actions on the server. You usually would have a server side script like a php script which you actually contact through your URL. That script would take care about either returning the requested data or update the data on the server.


You usually do not want to allow users to directly modify files on your server. On the wiki there's a server side highscore example where it stores the highscores in a mysql database. It comes with two serverside php scripts. One to add a new score and one to retrieve the current highscore list.


It's not really clear what you want to do. However you really have to be careful when you update or write files directly on the server. Users could upload malicious serverside script to your server if you're not careful. You really should read up on server security before you hack something together ^^.

avatar image gigos22 Bunny83 · Jan 18, 2021 at 12:21 PM 0
Share

I understand what you're saying, truly. But in my case it's not the users who gonna upload this file. It's a binary file that stores a record of all the people that played the game and is visible only for me in an ad$$anonymous$$ panel inside the game. Each time a player is finished playing, the game itself should upload a new file to override the old file, and to keep it updated.

Also, I have a lot of information about each player, about 10 properties if I recall correctly.

Show more comments

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

116 People are following this question.

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

Related Questions

WebGL Uncaught RangeError 2 Answers

Send a form to a HTTP server in rails 0 Answers

How do I get into my StreamingAssets folder for the Web? 0 Answers

How to free memory of UnityWebRequest? 1 Answer

http url not work in webgl (unity2019.3). 2 Answers


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