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
0
Question by stargamingentertainment · Nov 30, 2016 at 01:22 PM · c#unity 5dictionary

How to call the post function of the class Unity post get check www requests with success callback and error callbacks,

Hi Everyone this is my first time of asking a question of the whole 4 years of programing

im just wondering if any one could help point me in the right direction please?? or even better reply with the solusion please.

ive found this code on stackexchange.com link (http://codereview.stackexchange.com/questions/148550/unity-post-get-check-www-requests-with-success-callback-and-error-callbacks).

I cant seem to figure out how to call the post function passing through parameters for the dictionary.
this is partly how u call the post function

 MHSOnline.Post("register.php", "what do i have to put in here to add to the ", success => {
     // Success
 }, failure => {
     // Failure
 });

I've searched all other the internet but no luck, would someone please be able to help

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 namespace MugHeadStudios
 {
 /// <summary>
 /// MonoBehaviourEmpty is a dummy class added to run coroutines on temporary GameObjects
 /// </summary>
 public class MonoBehaviourEmpty : MonoBehaviour {}
 
 /// <summary>
 /// MHS online.
 /// </summary>
 public class MHSOnline
 {
     // PROPERTIES
 
     static public string Domain;
     static public string DirectoryPath;
     static public string PingFile;
 
     public delegate void WWWCallBack(string RequestedString = "");
     public delegate void WWWErrorCallBack(string RequestedString = "");
 
     // PUBLIC
 
     /// <summary>
     /// Post request to the specified URL with Data, optional CallBack and ErrorCallBack.
     /// </summary>
     /// <param name="File">File.</param>
     /// <param name="Data">Data.</param>
     /// <param name="CallBack">Call back.</param>
     /// <param name="ErrorCallBack">Error call back.</param>
     static public void Post(string URL, Dictionary<string, string> Data, WWWCallBack CallBack = null, WWWErrorCallBack ErrorCallBack = null)
     {
         MHSOnline.NetworkAvailable(success => {
             if(CallBack != null)
             {
                 GameObject newGameObject = new GameObject("Co-routine (POST)");
                 newGameObject.AddComponent<MonoBehaviourEmpty>().StartCoroutine(MHSOnline.IRequest(URL, Data, CallBack, newGameObject));
             }
         }, fail => {
             if(ErrorCallBack != null)
                 ErrorCallBack(fail);
         });
     }
 
     /// <summary>
     /// Get request to the specified URL, optional CallBack and ErrorCallBack.
     /// </summary>
     /// <param name="File">File.</param>
     /// <param name="CallBack">Call back.</param>
     /// <param name="ErrorCallBack">Error call back.</param>
     static public void Get(string URL, WWWCallBack CallBack = null, WWWErrorCallBack ErrorCallBack = null)
     {
         MHSOnline.NetworkAvailable(success => {
             if(CallBack != null)
             {
                 GameObject newGameObject = new GameObject("Co-routine (GET)");
                 newGameObject.AddComponent<MonoBehaviourEmpty>().StartCoroutine(MHSOnline.IRequest(URL, null, CallBack, newGameObject));
             }
         }, fail => {
             if(ErrorCallBack != null)
                 ErrorCallBack(fail);
         });
     }
 
     /// <summary>
     /// Calls back success or failue
     /// </summary>
     /// <param name="SuccessCallBack">Success call back.</param>
     /// <param name="ErrorCallBack">Error call back.</param>
     static public void NetworkAvailable(WWWCallBack SuccessCallBack = null, WWWErrorCallBack ErrorCallBack = null)
     {
         NetworkReachability networkReachability = Application.internetReachability;
 
         if(networkReachability == NetworkReachability.NotReachable)
             ErrorCallBack("NetworkReachability.NotReachable");
 
         GameObject newGameObject = new GameObject("Co-routine (Network)");
         newGameObject.AddComponent<MonoBehaviourEmpty>().StartCoroutine(MHSOnline.INetworkAvailable(success => {
             SuccessCallBack();
         }, fail => {
             ErrorCallBack(fail);
         }, newGameObject));
     }
 
     // PRIVATE
 
     static private IEnumerator INetworkAvailable(WWWCallBack SuccessCallBack = null, WWWErrorCallBack ErrorCallBack = null, GameObject TempObject = null)
     {
         WWW www = new WWW(MHSOnline.Domain+"/"+MHSOnline.DirectoryPath+"/"+MHSOnline.PingFile);
 
         yield return www;
 
         if(www.text == "true")
             SuccessCallBack();
         else
             ErrorCallBack(www.error);
 
         if(TempObject != null)
             MonoBehaviour.Destroy(TempObject);
     }
 
     static private IEnumerator IRequest(string File, Dictionary<string, string> Data = null, WWWCallBack CallBack = null, GameObject TempObject = null)
     {
         WWW www;
 
         if(Data != null)
         {
             WWWForm form = new WWWForm();
 
             foreach(KeyValuePair<string, string> KV in Data)
                 form.AddField(KV.Key, KV.Value);
 
             www = new WWW(MHSOnline.Domain+"/"+MHSOnline.DirectoryPath+"/"+File, form);
         }
         else
         {
             www = new WWW(MHSOnline.Domain+"/"+MHSOnline.DirectoryPath+"/"+File);
         }
 
         if(www != null)
             yield return www;
 
         if(CallBack != null)
         {
             string result = www.text;
             CallBack(result);
 
             if(TempObject != null)
                 MonoBehaviour.Destroy(TempObject);
         }
     }
 }   
 }



thank you in advance ricky

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

0 Replies

· Add your reply
  • Sort: 

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

6 People are following this question.

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

Related Questions

dictionary of words (as a key) and fbx files (as a value) 1 Answer

What's more efficient - ordering a list, or finding the smallest value? 2 Answers

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Destroying all GameObject values in a Dictionary 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