Unity3d 使用WWW 通讯 GET方法和POST方法
(一)GET方法
IEnumerator SendGet(string _url)
{
WWW getData = new WWW(_url);
yield return getData;
if(getData.error != null)
{
Debug.Log(getData.error);
}
else
{
Debug.Log(getData.text);
}
}
(二)POST方法
IEnumerator SendPost(string _url, WWWForm _wForm)
{
WWW postData = new WWW(_url, _wForm);
yield return postData;
if (postData.error != null)
{
Debug.Log(postData.error);
}
else
{
Debug.Log(postData.text);
}
}
调用两个方法
string requestAddress;
public void TestHttpSend()
{
//测试GET方法
StartCoroutine(SendGet(“http:gigvlkhj”));
//测试POST方法
WWWForm form = new WWWForm();
form.AddField("name", "张三");//int为接口名,6为传入的参数
StartCoroutine(SendPost(requestAddress, form)); //requestAddress为接口地址
}



