[英]How to call a method on server side from c#
我在堆栈溢出时得到此质量检查- 如何从客户端javascript函数调用服务器方法后面的代码?
但是,它是从javascript调用的函数,如何从c#进行调用。 我使用unity3d开发了一个ios应用程序,我之前没有做过。 有人知道怎么做吗?
提前致谢。
后端如下所示。 网址:https:// {服务器地址} /注册参数:
并返回:-user_id,int
我使用正确的参数运行服务器方法 ,如果参数正确,则返回int / user_id返回。
WWW unity3d类,这可能是您想要的。 WWW是
一个小的实用程序模块,用于检索URL的内容。
有关使用C#与服务器(PHP)进行交互的详细信息,我建议您使用这个unitywiki链接 。 您将需要执行本教程建议的类似操作。
IEnumerator GetData()
{
gameObject.guiText.text = "Loading Scores";
WWW hs_get = new WWW(highscoreURL);//highscoreURL this is ur url as u said
yield return hs_get;
if (hs_get.error != null)//checking empty or error response etc
{
print("There was an error getting the high score: " + hs_get.error);
}
else
{
gameObject.guiText.text = hs_get.text; // this is a GUIText that will display the scores in game.
}
}
您可以根据自己的规范定制的重置对象主要是WWW和Co-routine 。
表面上,将WWWForm
作为辅助参数添加到WWW
,然后将其post
到服务器。
using UnityEngine;
using System.Collections;
public class PostJsonDataScript : MonoBehaviour
{
// Use this for initialization
string Url;
void Start()
{
Url = "Url to the service";
PostData(100,"Unity");
}
// Update is called once per frame
void Update()
{
}
void PostData(int Id,string Name)
{
WWWForm dataParameters = new WWWForm();
dataParameters.AddField("Id", Id);
dataParameters.AddField("Name", Name);
WWW www = new WWW(Url,dataParameters);
StartCoroutine("PostdataEnumerator", Url);
}
IEnumerator PostdataEnumerator(WWW www)
{
yield return www;
if (www.error != null)
{
Debug.Log("Data Submitted");
}
else
{
Debug.Log(www.error);
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.