本文整理汇总了C#中System.UriBuilder.SetQueryparameter方法的典型用法代码示例。如果您正苦于以下问题:C# UriBuilder.SetQueryparameter方法的具体用法?C# UriBuilder.SetQueryparameter怎么用?C# UriBuilder.SetQueryparameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.UriBuilder
的用法示例。
在下文中一共展示了UriBuilder.SetQueryparameter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ExecuteFeed
public override WebResponse ExecuteFeed(string feedURL, IProvider provider, Token connectionToken, TRANSPORT_METHOD transportMethod)
{
UriBuilder ub;
/******** retrieve standard Fields ************/
ub = new UriBuilder(feedURL);
ub.SetQueryparameter(AccessTokenQueryParameterKey, connectionToken.AccessToken);
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ub.ToString());
request.Method = transportMethod.ToString();
//logger.LogContactsRequest(ub.ToString());
WebResponse wr;
try
{
logger.Debug("Executing " + feedURL + " using " + transportMethod.ToString());
wr = (WebResponse)request.GetResponse();
logger.Info("Successfully executed " + feedURL + " using " + transportMethod.ToString());
}
catch (Exception ex)
{
logger.Error(ErrorMessages.CustomFeedExecutionError(feedURL, null), ex);
throw new OAuthException(ErrorMessages.CustomFeedExecutionError(feedURL, null), ex);
}
return wr;
}
示例2: RequestForAccessToken
public void RequestForAccessToken()
{
UriBuilder ub = new UriBuilder(provider.AccessTokenEndpoint);
ub.SetQueryparameter("client_id", provider.Consumerkey);
ub.SetQueryparameter("client_secret", provider.Consumersecret);
ub.SetQueryparameter("code", connectionToken.Code);
ub.SetQueryparameter("redirect_uri", connectionToken.ProviderCallbackUrl);
ub.SetQueryparameter("grant_type", "authorization_code");
//logger.LogAuthorizationRequest(ub.ToString());
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ub.ToString());
string authToken = "";
try
{
logger.Debug("Requesting Access Token at " + ub.ToString());
using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
using (Stream responseStream = webResponse.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{
authToken = reader.ReadToEnd();
HandleAccessTokenResponse(authToken);
}
}
catch (Exception ex)
{
logger.Error(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), new QueryParameters()), ex);
throw new OAuthException(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), new QueryParameters()), ex);
}
}
示例3: RequestForAccessToken
public void RequestForAccessToken(TRANSPORT_METHOD method = TRANSPORT_METHOD.GET)
{
if (method != TRANSPORT_METHOD.GET && method != TRANSPORT_METHOD.POST)
throw new OAuthException("Invalid Verb used for requesting AccessToken. Supported verbs are GET/POST.");
UriBuilder ub = new UriBuilder(provider.AccessTokenEndpoint);
//logger.LogAuthorizationRequest(ub.ToString());
HttpWebRequest request;
if (method == TRANSPORT_METHOD.POST)
{
request = (HttpWebRequest)WebRequest.Create(ub.ToString());
string postData = "code=" + ConnectionToken.Code;
postData += ("&client_id=" + provider.Consumerkey);
postData += ("&client_secret=" + provider.Consumersecret);
postData += ("&redirect_uri=" + ConnectionToken.ProviderCallbackUrl);
postData += ("&grant_type=authorization_code");
request.Method = "POST";
byte[] byteArray = Encoding.UTF8.GetBytes(postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream();
// Write the data to the request stream.
dataStream.Write(byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close();
// Get the response.
}
else
{
ub.SetQueryparameter("client_id", provider.Consumerkey);
ub.SetQueryparameter("client_secret", provider.Consumersecret);
ub.SetQueryparameter("code", ConnectionToken.Code);
ub.SetQueryparameter("redirect_uri", ConnectionToken.ProviderCallbackUrl);
ub.SetQueryparameter("grant_type", "authorization_code");
request = (HttpWebRequest)WebRequest.Create(ub.ToString());
request.Method = "POST";
}
try
{
logger.Debug("Requesting Access Token at " + ub.ToString());
using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
using (Stream responseStream = webResponse.GetResponseStream())
using (StreamReader reader = new StreamReader(responseStream))
{
string authToken = reader.ReadToEnd();
HandleAccessTokenResponse(authToken);
}
}
catch (Exception ex)
{
logger.Error(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), new QueryParameters()), ex);
throw new OAuthException(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), new QueryParameters()), ex);
}
}
示例4: LoginCallback
internal static void LoginCallback(string response)
{
try
{
((IProviderConnect)ProviderFactory.GetProvider(InProgressToken().Provider)).LoginCallback(Utility.GetQuerystringParameters(response),
SocialAuthUser.OnAuthneticationProcessCompleted);
}
catch (Exception ex)
{
//User has specified to redirect here upon error instead fo throwing an error
if (!string.IsNullOrEmpty(SessionManager.ErrorURL))
{
UriBuilder errorUri = new UriBuilder(SessionManager.ErrorURL);
errorUri.SetQueryparameter("error_message", ex.Message);
errorUri.SetQueryparameter("error_type", ex.GetType().ToString());
HttpContext.Current.Response.Redirect(errorUri.Uri.AbsoluteUri.ToString());
}
else
throw;
}
}