本文整理汇总了C#中Hammock.RestRequest.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddHeader方法的具体用法?C# RestRequest.AddHeader怎么用?C# RestRequest.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Hammock.RestRequest
的用法示例。
在下文中一共展示了RestRequest.AddHeader方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SendRequest
public void SendRequest(RestRequest request, RequestBack callBack)
{
Action<string> errAction = (e1) =>
{
if (null != callBack)
{
DoubanSdkErrCode sdkErr = DoubanSdkErrCode.XPARAM_ERR;
callBack(new DoubanSdkResponse
{
//requestID = null != data ? data.requestId : "",
errCode = sdkErr,
specificCode = "",
content = e1,
stream = null
});
}
};
if (null == request)
{
errAction("request should`t be null.");
return;
}
m_Client.Authority = ConstDefine.PublicApiUrl;
m_Client.HasElevatedPermissions = true;
//添加鉴权
request.DecompressionMethods = DecompressionMethods.GZip;
request.Encoding = Encoding.UTF8;
IWebCredentials credentials = null;
if (null != DoubanAPI.DoubanInfo.tokenInfo && !string.IsNullOrEmpty(DoubanAPI.DoubanInfo.tokenInfo.access_token))
{
request.AddHeader("Authorization", string.Format("Bearer {0}", DoubanAPI.DoubanInfo.tokenInfo.access_token));
}
else
{
request.AddParameter("source", DoubanSdkData.AppKey);
}
request.AddParameter("curtime", DateTime.Now.ToString());
request.Credentials = credentials;
m_Client.BeginRequest(request, (e1, e2, e3) => AsyncCallback(e1, e2, callBack));
}
示例2: PrepareEchoRequest
public virtual RestRequest PrepareEchoRequest(string realm = "http://api.twitter.com")
{
var args = new FunctionArguments
{
ConsumerKey = _consumerKey,
ConsumerSecret = _consumerSecret,
Token = _token,
TokenSecret = _tokenSecret
};
var request = _protectedResourceQuery.Invoke(args);
request.Method = WebMethod.Get;
request.Path = string.Concat("account/verify_credentials", FormatAsString);
var credentials = (OAuthCredentials)request.Credentials;
var url = request.BuildEndpoint(_client);
var workflow = new OAuthWorkflow(credentials);
var method = request.Method.HasValue ? request.Method.Value : WebMethod.Get;
var info = workflow.BuildProtectedResourceInfo(method, request.GetAllHeaders(), url);
var query = credentials.GetQueryFor(url, request, info, method, TraceEnabled);
((OAuthWebQuery)query).Realm = realm;
var auth = query.GetAuthorizationContent();
var echo = new RestRequest();
echo.AddHeader("X-Auth-Service-Provider", url);
echo.AddHeader("X-Verify-Credentials-Authorization", auth);
return echo;
}
示例3: SendRegistrationToServer
static void SendRegistrationToServer(IEnumerable<RegistrationInfo> regs)
{
// I'm just so sorry about all this crap.
string separator = "¬";
string urls = "", tokens = "", names = "", types = "";
string version = WPVersion == OSVersion.WP8 ? "8" : "7";
foreach (var reg in regs)
{
urls += reg.ChannelUri + separator;
names += reg.User.ScreenName + separator;
tokens += Library.Encrypting.EncodeTokens(reg.User.Key, reg.User.Secret) + separator;
types += reg.Type + separator;
}
// Remove last separator
urls.Substring(0, urls.Length - 1);
tokens.Substring(0, tokens.Length - 1);
names.Substring(0, names.Length - 1);
types.Substring(0, types.Length - 1);
string postContents = "{\"AccessTokens\" : \"" + tokens + "\",\"PushUris\" : \"" + urls + "\",\"Usernames\" : \"" + names + "\",\"Types\" : \"" + types + "\",\"OSVersion\" : \"" + version + "\"}";
var request = new RestRequest();
request.Path = Library.SensitiveData.PushRegisterPostUriFormat;
request.Method = WebMethod.Post;
request.AddHeader("Content-Type", "application/json");
request.AddPostContent(Encoding.UTF8.GetBytes(postContents));
try
{
new RestClient().BeginRequest(request, (req, resp, s) =>
{
ReportRegisterToUser(resp);
});
}
catch (Exception)
{
}
}