當前位置: 首頁>>代碼示例>>C#>>正文


C# UriBuilder.MergeQueryString方法代碼示例

本文整理匯總了C#中System.UriBuilder.MergeQueryString方法的典型用法代碼示例。如果您正苦於以下問題:C# UriBuilder.MergeQueryString方法的具體用法?C# UriBuilder.MergeQueryString怎麽用?C# UriBuilder.MergeQueryString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.UriBuilder的用法示例。


在下文中一共展示了UriBuilder.MergeQueryString方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: DoHttpRequest

        /// <summary>
        /// Makes a signed request to the Twitter API based on the specified parameters.
        /// </summary>
        /// <param name="method">The HTTP method of the request.</param>
        /// <param name="url">The base URL of the request (no query string).</param>
        /// <param name="queryString">The query string.</param>
        /// <param name="postData">The POST data.</param>
        public virtual HttpWebResponse DoHttpRequest(string method, string url, NameValueCollection queryString, NameValueCollection postData) {

            // Check if NULL
            if (queryString == null) queryString = new NameValueCollection();
            if (postData == null) postData = new NameValueCollection();
            
            // Merge the query string
            if (queryString.Count > 0) {
                UriBuilder builder = new UriBuilder(url);
                url += (url.Contains("?") ? "&" : "") + builder.MergeQueryString(queryString).Query;
            }

            // Initialize the request
            HttpWebRequest request = (HttpWebRequest) WebRequest.Create(url);

            // Generate the signature
            string signature = GenerateSignature(method, url, queryString, postData);

            // Generate the header
            string header = GenerateHeaderString(signature);

            // Add the authorization header
            request.Headers.Add("Authorization", header);

            // Set the method
            request.Method = method;

            // Add the request body (if a POST request)
            if (method == "POST" && postData.Count > 0) {
                string dataString = SocialUtils.NameValueCollectionToQueryString(postData);
                //throw new Exception(dataString);
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = dataString.Length;
                using (Stream stream = request.GetRequestStream()) {
                    stream.Write(Encoding.UTF8.GetBytes(dataString), 0, dataString.Length);
                }
            }

            // Make sure we reset the client (timestamp and nonce)
            if (AutoReset) Reset();

            // Get the response
            try {
                return (HttpWebResponse) request.GetResponse();
            } catch (WebException ex) {
                if (ex.Status != WebExceptionStatus.ProtocolError) throw;
                return (HttpWebResponse) ex.Response;
            }

        }
開發者ID:EmilMoe,項目名稱:Skybrud.Social,代碼行數:57,代碼來源:OAuthClient.cs


注:本文中的System.UriBuilder.MergeQueryString方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。