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
2
Question by Hepallucion · Sep 06, 2014 at 02:48 AM · wwwwwwformrestput

PUT with WWWform

From what I can tell, WWW creates GET requets and WWWform will create POST requests. While these are great. I was hoping to follow more REST standards and also use PUT and DELETE.

Are these functions built into WWW or WWWform? If not, Sign me up to the developers and I'll get it in there. Modifying WWWform to allow for 'PUT' instead of 'POST' should be as simple as adding an optional parameter for 'HTTP_METHOD' Its quite literally the same thing only changing the first letters of the request from POST to PUT.

Anyone know a way? ...so that I don't need to badger Unity to let me develop it for them?

Love, Hepallucion

P.S. Yes, I could re-write my server to only use POST and GET, but I'd rather not, REST makes sense.

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 ina · Oct 01, 2014 at 02:36 AM 0
Share

http://feedback.unity3d.com/suggestions/support-put-in-www

3 Replies

· Add your reply
  • Sort: 
avatar image
2

Answer by Fehr · Jun 22, 2015 at 06:22 AM

Hey guys,

Here's a simple solution if you're working with MVC, but it can surely be be adapted to other platforms also. I initially wrote my client messaging layer around WebRequest, which has full support for CRUD but found that eventually with bigger data it caused unity to stutter, even when threaded.

When moving back to Unity's WWW I came across the lack of PUT and DELETE which my client was now coupled with. To avoid spending the time required to re-write all the PUT and DELETE MVC server functions, I came up with the following solution:

First, add the following header to your WWW request:

  var headers = new Dictionary<string, string>();
  headers.Add("X-HTTP-Method-Override", "PUT");

Then perform the WWW POST request as normal:

  var request = new UnityEngine.WWW(_uri, _putBytes, headers);
  yield return request;
  Debug.Log(request.text);

The server receives the sent POST request, but we area able to intercept the message by adding a new method handler which is run over the message before it is passed to the server's functions, and we change the request's method to PUT instead of POST:

 public class MethodOverrideHandler : DelegatingHandler
 {
     readonly string[] _methods = { "DELETE", "HEAD", "PUT" };
     const string _header = "X-HTTP-Method-Override";
  
     protected override Task<HttpResponseMessage> SendAsync(
         HttpRequestMessage request, CancellationToken cancellationToken)
     {
         // Check for HTTP POST with the X-HTTP-Method-Override header.
         if (request.Method == HttpMethod.Post && request.Headers.Contains(_header))
         {
             // Check if the header value is in our methods list.
             var method = request.Headers.GetValues(_header).FirstOrDefault();
             if (_methods.Contains(method, StringComparer.InvariantCultureIgnoreCase))
             {
                 // Change the request method.
                 request.Method = new HttpMethod(method);
             }
         }
         return base.SendAsync(request, cancellationToken);
     }
 }

Add the following line to the server solution's WebApiConfig.cs:

  public static void Register(HttpConfiguration config)
  {
       config.MessageHandlers.Add(new MethodOverrideHandler());
  ...

This way, without re-factoring any of the business layer for either the client or server we can overcome the lack of PUT and DELETE in Unity's WWW class. If anyone wants any more info on the process, there's a great article by Scott Hanselman that provided me with the solution.

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
0

Answer by rutter · Sep 06, 2014 at 03:50 AM

Unfortunately, Unity's built-in WWW class only supports GET and POST.

Fortunately, Unity supports just about any Mono-compatible .NET library you're able to import. You should be able to find plenty of suitable HTTP libraries online, and some of them are even built specifically to support Unity.

Comment
Add comment · Show 2 · 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 Hepallucion · Sep 06, 2014 at 03:56 PM 0
Share

Have any examples? Recommendations?

avatar image ina · Oct 01, 2014 at 02:36 AM 0
Share

http://feedback.unity3d.com/suggestions/support-put-in-www

avatar image
0

Answer by berg44 · Aug 11, 2016 at 01:31 PM

This is now completed in UnityEngine.Experimental.Networking as of Unity 5.2 and 5.3, with more platforms supported in further releases. Here is the official documentation: https://docs.unity3d.com/Manual/UnityWebRequest.html

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

7 People are following this question.

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

Related Questions

How do I use RESTful apis from Unity? 0 Answers

WWW, RESTful Service, and Threading 1 Answer

Getting info using WWW & PHP 3 Answers

How do I make a simple POST request to Amazon S3? 2 Answers

WWW/WWWForm, does Unity validate SSL certificates? 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