Unity3d之Http通訊GET方法和POST方法


轉:https://blog.csdn.net/dingkun520wy/article/details/49230853

 

(一)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);
  • }
  • }

調用兩個方法

 

    •  
      public void TestHttpSend()
    • {
    • //測試GET方法
    • StartCoroutine(SendGet( "http://kun.show.ghostry.cn/?int=5"));
    • //測試POST方法
    • WWWForm form = new WWWForm();
    • form.AddField( "int", "6");
    • StartCoroutine(SendPost( "http://kun.show.ghostry.cn/", form));
    • }


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM