コード例 #1
0
    public IEnumerator SendPlatfom(PlatformBase nProtocol)
    {
        string Url = ConfigsManager.Inst.GetClientConfig(ClientConfigs.PlatformIP);

        Dictionary <string, string> heads = new Dictionary <string, string>();

        heads.Add("cscode", Convert.ToString(nProtocol.m_Type));
        heads.Add("Method", "POST");
        heads.Add("Content-Type", "application/x-www-form-urlencoded");

        JsonData newData = new JsonData();

        nProtocol.marshal(ref newData);
        byte[] btBodys = Encoding.UTF8.GetBytes(newData.ToJson());

        WWW w = new WWW(Url, btBodys, heads);

        while (!w.isDone)
        {
            yield return(false);
        }
        if (w.error != null)
        {
            Debug.Log("SendPlatfom w.error" + w.error);
            yield return(false);
        }

        Dictionary <string, string> responseHeaders = w.responseHeaders;

        foreach (KeyValuePair <string, string> response in responseHeaders)
        {
            Debug.Log("responseHeaders Value : " + response.Value + " \nresponseHeaders Key : " + response.Key);
        }

        string cscode = responseHeaders["CSCODE"];

        if (cscode != string.Empty)
        {
            JsonData     jsonData = JsonMapper.ToObject(w.text);
            PlatformBase protocol = PlatformBase.JsonDataObject(Int32.Parse(cscode));
            if (protocol != null)
            {
                protocol.unmarshal(jsonData);
                AddTask(protocol);
            }
        }
    }