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
3
Question by Antho · May 06, 2011 at 06:26 PM · ioshttphttpwebrequestrestput

HTTP PUT in Unity for iOS?

Hello all,

I'm new here and I have a lot of fun developing with Unity, however I can't find a satisfying solution to my problem. I'm working on an iPhone app that has to send a HTTP PUT request to a REST server at some point.

The first thing I did was to look at Unity's WWW and WWWForm classes, however they support GET and POST only.

So I decided to use .Net 2.0's HttpWebRequest instead. I built my project with the full .Net 2.0 compatibility level (I used the subset until now), but I got the following error:

Uri putUri = new Uri("http://myserver.com/path");
HttpWebRequest request = WebRequest.Create(putUri) as HttpWebRequest;

That code works in Unity when I press play, but on the iPhone it throws:

MissingMethodException: Method not found: 'Default constructor not found...ctor() of System.Configuration.ExeConfigurationHost'. at System.Activator.CreateInstance (System.Type type, Boolean nonPublic) [0x00000] in :0 at System.Activator.CreateInstance (System.Type type) [0x00000] in :0 at System.Configuration.InternalConfigurationSystem.Init (System.Type typeConfigHost, System.Object[] hostInitParams) [0x00000] in :0 at System.Configuration.InternalConfigurationFactory.Create (System.Type typeConfigHost, System.Object[] hostInitConfigurationParams) [0x00000] in :0 at System.Configuration.ConfigurationManager.OpenExeConfigurationInternal (ConfigurationUserLevel userLevel, System.Reflection.Assembly calling_assembly, System.String exePath) [0x00000] in :0 at System.Configuration.ClientConfigurationSystem.get_Configuration () [0x00000] in :0 Rethrow as ConfigurationErrorsException: Error Initializing the configuration system. at System.Configuration.ClientConfigurationSystem.get_Configuration () [0x00000] in :0 at System.Configuration.ClientConfigurationSystem.System.Configuration.Internal.IInternalConfigSystem.GetSection (System.String configKey) [0x00000] in :0 at System.Configuration.ConfigurationManager.GetSection (System.String sectionName) [0x00000] in :0 at System.Net.WebRequest..cctor () [0x00000] in :0 Rethrow as TypeInitializationException: An exception was thrown by the type initializer for System.Net.WebRequest at REST.MakePutRequest (System.String data) [0x00027] in /Users/Antho/Unity Project/Assets/Scripts/Network/REST.cs:68

I originally thought the problem originated in using a string in WebRequest.Create(), but changing to an URI object didn't help. I tried to remove the HttpWebRequest casting and use WebRequest objects instead, it didn't help.

My REST.cs file contains other functions for GET, POST and DELETE methods and they also work in Unity and break in the iPhone app.

The last ditch solution would be to call an external function that's hooked to the HTTP framework in Objective-C, but I don't want to do that before I make sure I cannot use HttpWebRequest/WebRequest in Unity for iOS.

Thanks!

Antho

Related questions:

http://answers.unity3d.com/questions/37162/webrequest-create-problem http://answers.unity3d.com/questions/55176/www-put-method

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

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

2 Replies

· Add your reply
  • Sort: 
avatar image
1

Answer by chadcarter · Mar 16, 2015 at 10:06 PM

Assuming your server side webservice can support it, you can use the method override in an HTTP Header.

I'd like to see these HTTP verbs implemented as part of the WWW object, but in the mean time most server side technology can utilize the X-HTTP-Method-Override HTTP Header.

Make sure you pass the value through the X-HTTP-Method-Override header: headers["X-HTTP-Method-Override"] = "PUT"; (or PATCH, DELETE, GET, POST, etc)

byte[] postData = Encoding.UTF8.GetBytes(json);

Dictionary headers = new Dictionary(); headers.Add("Content-Type", "application/json"); headers.Add("Accept", "application/json"); headers["X-HTTP-Method-Override"] = "PUT"; www = new WWW("http://webservice-location/" + playerInfo.id.ToString(), postData, headers); yield return www;

I use this with Azure Mobile Services quite nicely.

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 rijkens · Jan 11, 2018 at 01:48 PM

Below the full example code can be found to do a PUT request in Unity:

 using UnityEngine;
 using System.Collections;
 using UnityEngine.Networking;
 using System.Collections.Generic;
 
 public class PutRequest : MonoBehaviour 
 
 {
     public string YourPostData;
     public string APIUrl;
 
     void Start() 
     {
         //starts the put request example
         StartCoroutine(PUTrequest());
     }
 
 
     IEnumerator PUTrequest()
     {
     // this string is the data that needs to be send to the server
         byte[] postData = System.Text.Encoding.UTF8.GetBytes(YourPostData);
 
         // The headers settings in order for the server to accept the PUT request
         Dictionary<string, string> headers = new Dictionary<string, string>();
         headers.Add("Content-Type", "application/json"); 
         headers.Add("Accept", "application/json"); 
         headers["X-HTTP-Method-Override"] = "PUT"; 
 
         // the postData and header settings are send to the server
         WWW api = new WWW(APIUrl, postData, headers); 
 
         yield return api;
 
         // the response of the server can be read in the Debug Log
         Debug.Log(api.text);
     }
         
 }
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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

Get data from REST works on Unity but not on Android Device 1 Answer

IOS HTTP GET with Authorization Header not being sent 0 Answers

Why do I get Parse error (code 400) from Google Ftiness API in Unity? 0 Answers

HTTP WebRequest with iOS Stripping 1 Answer

Does overriding UnityWWWRequestDefaultProvider works for UnityWebRequest? 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