コード例 #1
0
        public bool UpdateStatus(string message)
        {
            //NewRequest();
            message = PercentageEncoding.EncodeURL(message);
            string appURL = ApiPoint.UpdateStatusJson + message;

            var authzHeader = GenerateAuthzHeader(appURL, "POST");
            var request     = (HttpWebRequest)WebRequest.Create(appURL);

            request.Method                    = "POST";
            request.PreAuthenticate           = true;
            request.AllowWriteStreamBuffering = true;
            request.Headers.Add("Authorization", authzHeader);

            using (var response = (HttpWebResponse)request.GetResponse())
            {
                if (response.StatusCode != HttpStatusCode.OK)
                {
                    string output = response.StatusDescription;
                    return(true);
                }
            }

            return(false);
        }
コード例 #2
0
        WebRequest CreateRequest(string method,
                                 string url, Dictionary <string, string> parameters)
        {
            string encodedParams = PercentageEncoding.EncodeParameters(parameters);

            WebRequest request;

            if (method == "GET")
            {
                request = WebRequest.Create(string.Format("{0}?{1}", url, encodedParams));
            }
            else
            {
                request = WebRequest.Create(url);
            }

            request.Method      = method;
            request.ContentType = "application/x-www-form-urlencoded";
            request.Headers.Add("Authorization", MakeOAuthHeader(method, url, parameters));

            if (method == "POST")
            {
                byte[] postBody = new ASCIIEncoding().GetBytes(encodedParams);
                using (Stream stream = request.GetRequestStream())
                {
                    stream.Write(postBody, 0, postBody.Length);
                }
            }

            return(request);
        }