本文整理汇总了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;
}
}