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
7
Question by KvanteTore · Mar 25, 2010 at 06:56 PM · webrestful

Accessing RESTful web apis from unity

Is it possible to get the WWW class to use any other http verb than GET or POST? I'm trying to access web apis wich relies on the correct the http verb for an operation.

Most of the time my apps will be running in the web player, so I guess I could create some javascript functions exposing the jquery $.ajax() or similar and call the javascript from unity, but that excludes debugging in the editor.

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 misher · Mar 08, 2019 at 10:50 AM 0
Share

You may be interested in this Unity-specific Restful API client generator https://github.com/kolodi/UnityOpenApi

8 Replies

· Add your reply
  • Sort: 
avatar image
4
Best Answer

Answer by KvanteTore · Mar 29, 2010 at 10:04 PM

Silly me, I just realized I can use the System.Net.HttpWebRequest, it provides me with all the http-goodness I care for.

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 qJake · Mar 29, 2010 at 10:11 PM 0
Share

Oh, that's all you wanted to know? I guess I read into the question a bit more than I thought... people here tend to ask more complicated questions than they really intend to, heh. ;)

avatar image KvanteTore · Mar 30, 2010 at 07:45 AM 0
Share

:) I might have spoken out too soon though. I'm having a some problems actually getting HttpWebRequest to perform requests from within Unity

avatar image KvanteTore · Mar 30, 2010 at 09:58 AM 0
Share

never$$anonymous$$d. all is working well with the HttpWebRequest :)

avatar image KvanteTore · Apr 25, 2010 at 12:56 PM 0
Share

never$$anonymous$$d the never$$anonymous$$d. It turns out that HttpWebRequest is not available in the webplayer :(

avatar image misher KvanteTore · Mar 08, 2019 at 10:47 AM 0
Share

webplayer is now deprecated, UnityWebRequest is working in WebGL builds. In fact, it is what I'm using in https://github.com/kolodi/UnityOpenApi - unity friendly restful client generator

avatar image Fragmental · Jun 13, 2014 at 02:53 AM 0
Share

Uniweb might work with the webplayer, though I've never tried it personally. I have used uniweb for mobile and desktop and it has worked for my needs.

Show more comments
avatar image
9

Answer by Lowgain · Feb 03, 2012 at 01:23 AM

"The HTTP protocol only supports the GET and POST operations" <- not true

Comment
Add comment · Show 1 · 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 tibithegreat · Nov 18, 2013 at 09:10 AM 0
Share

Not sure where you copy pasted that from, but it's not true. http://en.wikipedia.org/wiki/Hypertext_Transfer_Protocol#Request_methods

avatar image
2

Answer by Mike McFarland · Mar 29, 2013 at 01:58 PM

Even though this is an old question I wanted to chime in. There are a few solutions for using rest in Unity. They all involve libraries that re-implement http over sockets. Here's one in particular: https://github.com/andyburke/UnityHTTP

It's too bad that the built in Unity http api doesn't support more verbs, and that the System.Net

classes aren't functional in webplayer.

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 psykojello2 · May 12, 2014 at 03:47 AM 0
Share

I know the UnityHTTP library you posted isn't yours, but would you know if it needs to be compiled or if it can be used as is in Unity?

It seems to be looking for the UnityEngine and $$anonymous$$onoBehavior namespace.

Sorry if that's a stupid question :) This is the first time I've had to use external libraries in Unity.

avatar image Antarxes · Sep 18, 2014 at 06:58 PM 0
Share

I'm considering using UnityHTTP for my project but I was wondering what the other solutions are that you mentioned. Is UnityHTTP just the best one available and that you would recommend?

The functionality would serve but we were looking for something that is a bit more developed.

avatar image Thorny2000 · Oct 20, 2014 at 09:09 PM 0
Share

Hey @Antarxes, I'm looking at this stuff and UnityHTTP too. How did you get on?

avatar image Antarxes · Oct 20, 2014 at 11:01 PM 0
Share

@G$$anonymous$$T Hey there, we considered using WA$$anonymous$$ (gonna have to search for it, I forgot who made it) but we eventually ended up deciding to spend the money on the $$anonymous$$atrix library for X$$anonymous$$PP. We can send receive our messages to Unity that way. Not much of a solution for Indie devs though. It's working rather well but development is still early and no heavy lifting is being done yet.

avatar image fedor.shubin · Jan 28, 2015 at 02:45 PM 0
Share

We've created our REST SD$$anonymous$$ on the shoulders of UnityHTTP. It provides API similar to restangular, implements path building, error handling, and other useful things. You can find it here: https://github.com/vedi/restifizer-unity3d

Show more comments
avatar image
2

Answer by kmfjsc · Nov 30, 2016 at 09:23 AM

I've done for doing this below. Let's go : ==>

 using UnityEngine;
 using UnityEngine.UI;
 using System.Collections;
 using System.Collections.Generic;
 public class btnGetData : MonoBehaviour {
  void Start()
  {
      gameObject.GetComponent<Button>().onClick.AddListener(TaskOnClick);
  }
  IEnumerator WaitForWWW(WWW www)
  {
      yield return www;
     
      
      string txt = "";
      if (string.IsNullOrEmpty(www.error))
          txt = www.text;  //text of success
      else
          txt = www.error;  //error
      GameObject.Find("Txtdemo").GetComponent<Text>().text =  "++++++\n\n" + txt;
  }
  void TaskOnClick()
  {
      try
      {
          GameObject.Find("Txtdemo").GetComponent<Text>().text = "starting..";   
          string ourPostData = "{\"plan\":\"TESTA02\"";
          Dictionary<string,string> headers = new Dictionary<string, string>();
          headers.Add("Content-Type", "application/json");
          //byte[] b = System.Text.Encoding.UTF8.GetBytes();
          byte[] pData = System.Text.Encoding.ASCII.GetBytes(ourPostData.ToCharArray());
          ///POST by IIS hosting...
          WWW api = new WWW("http://192.168.1.120/si_aoi/api/total", pData, headers);
          ///GET by IIS hosting...
          ///WWW api = new WWW("http://192.168.1.120/si_aoi/api/total?dynamix={\"plan\":\"TESTA02\"");
          StartCoroutine(WaitForWWW(api));
      }
      catch (UnityException ex) { Debug.Log(ex.Message); }
  } 
 }
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 Extrawrigley · Mar 22, 2017 at 01:46 PM 0
Share

Exactly what i was looking for. Thanks mate!

avatar image Zaddo67 · Apr 01, 2017 at 02:09 AM 0
Share

Perfect. Thanks.

avatar image
0

Answer by qJake · Mar 25, 2010 at 10:06 PM

The HTTP protocol only supports the GET and POST operations. REST is not part of HTTP, they're two completely different things. REST is just a specification for how the server acts and sends the data. If the data is over HTTP, you can get the REST data just like you would get the contents of a webpage (using GET). HTTP POST is only for posting forms or files back to the webserver. Any time you want to get anything off of a webserver, you use GET.

http://en.wikipedia.org/wiki/REST

http://en.wikipedia.org/wiki/HTTP

Reading both of those articles would probably be to your benefit.

Comment
Add comment · Show 6 · 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 duck ♦♦ · Mar 25, 2010 at 10:17 PM -1
Share

Good answer. I would just add a $$anonymous$$or correction that POST requests aren't solely for just sending information to the server. All POST requests return a response, much like the return value of a function, so you can retrieve information from the server via a POST request too.

avatar image KvanteTore · Mar 25, 2010 at 10:25 PM 1
Share

From the linked wikipedia article: "...HTTP defines eight methods (sometimes referred to as "verbs")...".

I am aware that rest is not a part of http, but it is an architecture often implemented over http. The idea (when implementing over http at least) is to map resources to urls and use the verbs defined by http to define operations on those resources.

I'm not trying to argument that this is the best way to design web apis, but I still would like to use the other 6 http verbs so I can communicate with the existing web apis out there.

avatar image KvanteTore · Mar 28, 2010 at 12:09 PM 1
Share

I'm sorry, but I completely disagree that GET and POST are the only useful verbs. HEAD is useful to see if there are changes to the document, $$anonymous$$ETE and PUT can be used to delete and insert documents. REST certainly is not a http verb, but an architecture describing a way to structure a web api, and one of the ideas is to use the http verbs to describe the action to be taken on a resource. Perhaps you should read the two wikipedia articles you linked to. All I want to do is to have a bit more control over my http requests by setting the http verb, but forget I asked...

avatar image Yokimato · Mar 26, 2013 at 07:59 PM 3
Share

"GET and POST are the only useful verbs" This is 100% Bullplop and FUD! Further, statements like "...and REST isn't even one of those verbs" show me you have NO concept of what HTTP or REST. Reading your own posted articles would do YOU benefit. I've never read a more wrong posting on this site.

avatar image zeelot · Apr 16, 2013 at 05:00 PM 1
Share

This is total nonsense. HTTP does support more than just GET and POST. It's really unfortunate that the WWW class is as limited as it is. if you look at requests going out on the Chrome dev tools, you'll see just how simple an HTTP request is to build.

Show more comments
  • 1
  • 2
  • ›

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

14 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

Related Questions

Cookie not correctly set in UnityWebRequest in 2018.3 1 Answer

Set Content-Length header for UnityWebRequest POST requests in 2017.3? 1 Answer

How would I go about getting the results of a javascript variable to a string inside script? 3 Answers

How to access StartCoroutine in a static way 3 Answers

Once Unity loads (Web player) how do I prevent it from being *Focused*? 0 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