コード例 #1
0
 Request Prepare(Request r)
 {
     foreach (DictionaryEntry e in _data)
     {
         r.AddQuery(e.Key.ToString(), e.Value);
     }
     return(r);
 }
コード例 #2
0
        private Net.WebRequest Generate(Request r, int retry)
        {
            // need to sign the request
            // we use a method similar to AWS signature version 2 (with a few changes to better support JSON and not sort the qs)
            Net.WebRequest request = null;

            // log id
            r.AddQuery("logid", GenLogId(r, retry));

            // timestamp
            if (Time.Valid)
            {
                r.AddQuery("ts", Time.Now);
            }

            if (retry > 0)
            {
                r.AddQuery("retry", retry);
            }

            if (r.isPost)
            {
                if (r.data.ContainsKey("nonce") == false)
                {
                    r.AddData("nonce", EB.Sparx.Nonce.Generate());
                }
                // post as json
                string json = JSON.Stringify(r.data);
                byte[] body = Encoding.GetBytes(json);

                string sig = Sign(r, "POST", json);
                r.AddQuery("sig", sig);

                Hashtable headers = Johny.HashtablePool.Claim();
                headers["Content-Type"] = "application/json";
                if (!string.IsNullOrEmpty(_cookie))
                {
                    headers["Cookie"] = _cookie;
                }

                EB.Debug.Log("<color=#42fe79>[Post]</color>: " + r.url + "\n" + json);

                request = new Net.WebRequest(r.url, body, headers);
            }
            else
            {
                r.query.Remove("sig");
                string sig = Sign(r, "GET", QueryString.StringifySorted(r.query));
                r.AddQuery("sig", sig);

                EB.Debug.Log("<color=#42fe79>[Get]</color>: " + r.url);

                if (!string.IsNullOrEmpty(_cookie))
                {
                    Hashtable headers = Johny.HashtablePool.Claim();
                    headers["Cookie"] = _cookie;
                    request           = new Net.WebRequest(r.url, headers);
                }
                else
                {
                    request = new Net.WebRequest(r.url);
                }
            }

            request.OnDataCallback = r.dataCallback;
            request.OnHeaders      = r.headersCallback;

            request.Start();
            return(request);
        }