Esempio n. 1
0
        /**
         * This is the lowest level request method. Use higher level if possible.
         */
        public JObject Request(string uri, string method, ClientType client, JObject parameters, JObject headerOverrides, RequestHandler handler, object state)
        {
            JObject request = new JObject();
            request.Add("parameters", parameters);
            JObject header = new JObject();
            if (m_token != null)
            {
                string t = GenerateToken(method);
                header.Add("token", t);
            }
            header.Add("session", m_sid);

            if (client == ClientType.HTML)
                header.Add("client", "htmlshark");
            else if (client == ClientType.JSQueue)
                header.Add("client", "jsqueue");
            else
                throw new Exception("ClientType not supported.");

            header.Add("clientRevision", "20101012.37");
            header.Add("privacy", 0);
            // Somehow this uuid is important, and I don't really know what it is, the UUID of the JSQueue flash object ?
            header.Add("uuid", "6BFBFCDE-B44F-4EC5-AF69-76CCC4A2DAD0");
            header.Add("country", m_countryObj);
            request.Add("header", header);
            request.Add("method", method);

            if (headerOverrides != null)
            {
                IDictionaryEnumerator e = headerOverrides.GetEnumerator();
                while (e.MoveNext())
                {
                    if (header.ContainsKey(e.Key))
                        header[e.Key] = e.Value;
                    else
                        header.Add(e.Key, e.Value);
                }
            }
            string requestStr = request.ToString().Replace("\n", "").Replace(" ", "").Replace("\r", "");
            CookieAwareWebClient wc = new CookieAwareWebClient(m_cc);
            wc.UploadStringCompleted += new UploadStringCompletedEventHandler(GSRequestHandler);
            wc.UploadStringAsync(new Uri(uri + "?" + method), "POST", requestStr, new object[]{ handler, state });
            if(RequestSent != null)
                RequestSent(this, requestStr);
            return request;
        }