zoukankan      html  css  js  c++  java
  • Get and Post(Unity3D六个发展)

    猴子原创,欢迎转载。

    转载请注明: 转载自Cocos2D开发网–Cocos2Dev.com,谢谢!

    原文地址: http://www.cocos2dev.com/?p=565

    unity3d中的www直接提供了web请求服务。使用也很easy。

    using UnityEngine;
    using System.Collections.Generic;
    using System.Collections;
    
    public class WebManager : MonoBehaviour {
    
    	// Use this for initialization
    	void Start () 
    	{
    		// Request by get
    		StartCoroutine(Get("http://www.cocos2dev.com/"));
    
    		// Request by post
    		Dictionary<string, string> dic = new Dictionary<string, string> ();
    		dic.Add("userId", "6001345679887");
    		dic.Add("eventId", "10018");
    		StartCoroutine(Post("http://192.168.1.102/api.php", dic));
    	}
    	
    	// Update is called once per frame
    	void Update () 
    	{
    	
    	}
    
    	// Post
    	IEnumerator Post(string url, Dictionary<string, string>postData) 
    	{
    		WWWForm form = new WWWForm();
    		foreach(KeyValuePair<string, string> postArg in postData) 
    		{
    			form.AddField(postArg.Key, postArg.Value);
    		}
    		
    		WWW www = new WWW(url, form);
    		yield return www;
    		
    		if (www.error != null) 
    		{
    			Debug.Log("error is :"+ www.error);
    		} 
    		else
    		{
    			Debug.Log("request result :" + www.text);
    		}
    	}
    	
    	// Get
    	IEnumerator Get(string url) 
    	{
    		WWW www = new WWW (url);
    		yield return www;
    		
    		if (www.error != null) 
    		{
    			Debug.Log("error is :"+ www.error);
    		} 
    		else 
    		{
    			Debug.Log("request result :" + www.text);
    		}
    	}
    }


    版权声明:本文博客原创文章,博客,未经同意,不得转载。

  • 相关阅读:
    hdu 4638 Group 线段树
    hdu 4635 Strongly connected 强连通分量
    hdu 4604 Deque
    hdu 1000 A + B Problem
    数组相关
    文本文件相关
    硬件电路中VCC,VDD,VEE,VSS有什么区别
    VIPM链接LabVIEW问题
    Touch实现轻扫
    touchesMoved 实现拖拽
  • 原文地址:https://www.cnblogs.com/gcczhongduan/p/4712524.html
Copyright © 2011-2022 走看看