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
1
Question by gardian06 · Feb 20, 2013 at 03:45 PM · wwwwwwform

Including POST request data for RESTfull server

I am still a little unclear on how to handle POST request data especially bound for a RESTfull server for the purpose of quarrying a database. currently we have a noSQL database in place that expects curl-i notation. (I don't know how this directly works was just given list of "acceptable" commands)

currently all I know how to do is actions that require just a url (getting X number of records at known location [Yrecords starting at positionX]). but what I need to implement is searching which requires a special formatted POST request, and the documentation is really no help at all. the expected statement in curl-i is:

 curl -i "urlTarget" -XPOST -d'{keyValue:"targetValue"}'

so what/how do I give this to the server using the WWW class call? do I need to wrap this -d'{keyValue:"targetValue"}' in a WWWForm, hand it using a byte[], or do more rigorous string magic on it?

Comment
Add comment · Show 4
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 gardian06 · Feb 20, 2013 at 10:58 PM 0
Share

is there anywhere I can look specifically for more in depth information on the WWWForm besides here, or even more in depth information of the different WWW class constructors?

even a tutorial, or a functional demonstration program

avatar image gardian06 · Feb 21, 2013 at 02:49 PM 0
Share

is there really nothing available?

avatar image gardian06 · Feb 21, 2013 at 08:30 PM 0
Share

I found something similar for the formatting here, but when I try this feeding in "keyValue" as formArg1, and "targetValue" as formArg2 the server tells me that these are bad requests even if I take the search data directly from a record I just pulled.

anyone?

avatar image gardian06 · Feb 22, 2013 at 04:02 PM 0
Share

additional information available in forums here help in either of these places would mean success of project as this is a viability project at its core.

4 Replies

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

Answer by gardian06 · Mar 05, 2013 at 08:37 PM

if post request data must be given in the immediate header as with the question then it should be placed in a hashtable, and then encoded into a WWW call as a header like so:

 var encoding = new System.Text.UTF8Encoding();
 var postHeader = new Hashtable();
 
 postHeader.Add("Content-Type", "text/json");
 postHeader.Add("Content-Length", jsonString.Length);
 
 print("jsonString: " + jsonString);
 var request = WWW(postScoreURL, encoding.GetBytes(jsonString), postHeader);
 
 yield request;

though keep in mind that even though the encoding reads as json the formatting might not be strict json, but a modification thereof.

in regards to doing this through WWWForm this requires either talking to a specific script on the server, or talking to the only script on the given server, and is detailed in my answer here

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
1

Answer by tzamora · May 07, 2013 at 04:19 PM

In my case to connect to .net web api (rest) I did this:

         WWWForm form = new WWWForm();
         
         form.AddField("facebookID", facebookID);

         //
         // I dont know why, but I have to put the parameters repeated in the url and in the WWWForms
         // If I put the post argument only in the WWWForm or only in the url the request returns 404
         //

         string url = "http://site.net/api/facebookusers/?facebookID=" + facebookID;
         
         Hashtable header = new Hashtable();
         
         header.Add("Content-Type", "application/x-www-form-urlencoded");
         
         WWW www = new WWW(url, form.data, header);
 
         StartCoroutine( WaitForRequest( www ) );
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 nventimiglia · Feb 22, 2013 at 05:22 PM

I just finished writing a ASP.NET MVC4 API service to talk with Unity3d. My controller logic talks to a live database (via entity), but that shouldn't matter.

Unity side my logic looks something like this.

    var form = new WWWForm();
 
         form.AddField("key", key);
         form.AddField("content", content);
 
         //Secure method
         var www = new WWW(Domain+SaveUrl, form.data, AuthCookie.SessionCookie);
 
         yield return www;
 
         if (!string.IsNullOrEmpty(www.error))
         {
             callback.Invoke(new ApiResult
             {
                 HasError = true,
                 Message = www.error
             });
         }
         else
         {
             callback.Invoke(new ApiResult());
         }

The callback is a action delegate for communicating results back to consumers of this service client.

Comment
Add comment · Show 3 · 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 gardian06 · Feb 25, 2013 at 06:05 AM 0
Share

in your 2 lines including form.AddField() what to do those correlate too? this is the part I think I am getting wrong, but the responses of the server is only the 1 if it is incorrect.

avatar image nventimiglia · Mar 05, 2013 at 08:43 PM 0
Share

Those are the parameters i am sending to my server side action.

ie : Login : username/value password/value

avatar image Seattlefella · Mar 24, 2013 at 11:22 PM 0
Share

Can you post the $$anonymous$$VC side controller code for this example? Like you I have a running $$anonymous$$VC 4 api tied to a database tied to Unity3d. I have no issues sending files, and other data to unity3d. But when I try to post data from unity3d to the $$anonymous$$VC API the form data is not bound to the control function. ie. the form data always come in as null. I have found a number of web postings on $$anonymous$$VC 4 and difficulties with API binding.

$$anonymous$$any Thanks

avatar image
0

Answer by gaminggal39 · Nov 12, 2018 at 07:50 AM

Watch this video to solve :https://www.youtube.com/watch?v=FChVgb6EXGk&t=133s

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

13 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

Related Questions

How to Upload multiple files to a server using UnityWebRequest.Post(); 3 Answers

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

Listing packages from web directory and loading them during runtime 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