String cookie_id = ""; void SendDdata(string data, string addr) { WWWForm form = new WWWForm(); Hashtable hash = new Hashtable(); hash.Add("Cookie", cookie_id); form.AddField("data",data); WWW www = new WWW(서버 IP, form.data, hash); StartCoroutine(WaitForRequest(www)); } private IEnumerator WaitForRequest(WWW www) { yield return www; // check for errors if (www.error == null) { Debug.Log("WWW Ok!: " + www.text); if (www.responseHeaders.ContainsKey("SET-COOKIE")){ cookie_id = www.responseHeaders["SET-COOKIE"]; } } else { Debug.Log("WWW Error: " + www.error); } }




핵심은  Cookie를 Hastable를 만들어 추가해서 보내는겁니다. 


쿠키가 없다면

WWW www = new WWW(서버 IP, form) 해당 형태로 보내겠지만


Hastable을 생성해서 추가할때는 꼭 form이 아닌 바이트배열 형태인 form.data로 바꿔줘야 합니다.


그래서

WWW www = new WWW(서버 IP, form.data, hash); 형태가 되는거지요 ^ㅡ^






신고
  1 using UnityEngine; 
  2 using System.Collections; 
  3 using System.Collections.Generic; 
  4 using System.Text; 
  5 using System.IO; 
  6 using System.Net;
  7 
  8 public class WWWWiki : MonoBehaviour 
  9 
 10 { 
 11     // Use this for initialization 
 12     void Start() 
 13     {          
 14 
 15     } 
 16 
 17     // Update is called once per frame 
 18 
 19     void Update() 
 20     { 
 21 
 22     } 
 23 
 24     void OnGUI() 
 25     {
 26 
 27     } 
 28 
 29     public WWW GET(string url) 
 30     { 
 31         WWW www = new WWW(url); 
 32         StartCoroutine(WaitForRequest(www)); 
 33         return www; 
 34     } 
 35 
 36     public WWW POST(string url, Dictionary<string, string> post) 
 37     { 
 38 
 39         WWWForm form = new WWWForm(); 
 40 
 41         foreach (KeyValuePair<string, string> post_arg in post) 
 42         { 
 43 
 44             form.AddField(post_arg.Key, post_arg.Value); 
 45 
 46         } 
 47 
 48         WWW www = new WWW(url, form); 
 49         StartCoroutine(WaitForRequest(www)); 
 50         return www; 
 51 
 52     } 
 53 
 54 
 55     private IEnumerator WaitForRequest(WWW www) 
 56     { 
 57         yield return www; 
 58         // check for errors 
 59         if (www.error == null) 
 60         { 
 61             Debug.Log("WWW Ok!: " + www.text); 
 62         } 
 63         else 
 64         { 
 65             Debug.Log("WWW Error: " + www.error); 
 66         } 
 67     } 
 68 
 69 }



Stack Over flow 에서 주섰습니다 ^ㅡ^







신고

+ Recent posts

티스토리 툴바