Knetik.KnetikRequest.SetHeader C# (CSharp) Method

SetHeader() public method

public SetHeader ( string name, string value ) : void
name string
value string
return void
        public void SetHeader(string name, string value)
        {
            name = name.Trim ();
            value = value.Trim ();
            if (!headers.ContainsKey (name))
                headers[name] = new List<string> ();
            headers[name].Clear ();
            headers[name].TrimExcess();
            headers[name].Add (value);
        }

Usage Example

Beispiel #1
0
        protected KnetikRequest CreateRequest(string path, string body = "[]", string method = "post", int timestamp = -1, string serviceBundle = null, bool isForm = false)
        {
            if (timestamp == -1) {
                TimeSpan t = (DateTime.UtcNow - new DateTime (1970, 1, 1));
                timestamp = (int)t.TotalSeconds;
            }

            string url = BuildUrl (path, serviceBundle);

            System.Text.ASCIIEncoding encoding=new System.Text.ASCIIEncoding();
            byte[] data = encoding.GetBytes(body);

            KnetikRequest req = new KnetikRequest (method, url, data);

            if (isForm) {
                req.SetHeader("Content-type", "application/x-www-form-urlencoded");
            } else {
                req.SetHeader("Content-type", "application/json");
                req.SetHeader("Accept", "application/json");
            }
            req.SetHeader("User-Agent", "Knetik Unity SDK");

            if (AccessToken != null && AccessToken != "")
            {
                req.SetHeader("Authorization", "Bearer " + AccessToken);
            }

            return req;
        }
All Usage Examples Of Knetik.KnetikRequest::SetHeader