Exemple #1
0
 /// <summary>
 /// 生成oauth uri
 /// </summary>
 /// <param name="redirectUri">重定向uri</param>
 /// <returns></returns>
 public string OAuthUri(string redirectUri)
 {
     PrismParams p = new PrismParams();
     p.Add("client_id", this._client.Key);
     p.Add("redirect_uri", redirectUri);
     return this._client.Server + "/oauth/authorize?" + p.ToString();
 }
Exemple #2
0
        private PrismResponse action(string method, string api, PrismParams parameters)
        {
            try
            {
                PrismParams headers = new PrismParams { };
                PrismParams getParams = new PrismParams { };
                PrismParams postParams = new PrismParams { };
                string uristr = this.Server + "/" + api;
                Uri uri = new Uri(uristr);

                bool use_query_in_uri = false;

                switch (method)
                {
                    case "GET":
                        getParams = parameters;
                        use_query_in_uri = true;
                        break;
                    default:
                        postParams = parameters;
                        break;
                }

                this.FixParams(method, uri.AbsolutePath, parameters, headers, getParams, postParams);

                if (use_query_in_uri)
                {
                    uristr = uristr + "?" + getParams.ToString();
                }
                HttpWebRequest request = this.CreateRequest(uristr);

                request.Method = method;

                if (use_query_in_uri == false)
                {
                    byte[] postData = postParams.ToBytes();
                    request.ContentLength = postData.Length;
                    request.ContentType = "application/x-www-form-urlencoded";

                    using (var dataStream = request.GetRequestStream())
                    {
                        dataStream.Write(postData, 0, postData.Length);
                        dataStream.Close();
                    }
                }

                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                return new PrismResponse(response);
            }
            catch (WebException e)
            {
                try
                {
                    HttpWebResponse response = (HttpWebResponse)e.Response;
                    throw new PrismException(e, response);
                }
                catch (PrismException)
                {
                    throw e;
                }
                catch
                {
                    throw e;
                }
            }
            catch
            {
                throw;
            }
        }