本文整理汇总了C#中IRestRequest.AddHeader方法的典型用法代码示例。如果您正苦于以下问题:C# IRestRequest.AddHeader方法的具体用法?C# IRestRequest.AddHeader怎么用?C# IRestRequest.AddHeader使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IRestRequest
的用法示例。
在下文中一共展示了IRestRequest.AddHeader方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Authenticate
public void Authenticate(IRestClient client, IRestRequest request)
{
request.AddHeader("Authorization", string.Format("Bearer {0}", AccessToken));
if (HasSharedLink())
{
request.AddHeader("BoxApi", string.Format("shared_link={0}", SharedLink));
}
}
示例2: Authenticate
/// <summary>
/// Adds the necessary authentication to the request.
/// </summary>
/// <param name="client">The RestClient to authenticate.</param>
/// <param name="request">The RestClient to authenticate.</param>
public void Authenticate(IRestClient client, IRestRequest request)
{
string url = string.Format("{0}{1}", _hashHostName, request.Resource);
string gmtTime = DateTime.Now.ToUniversalTime().ToString("R");
string hash = GetPAPIHash(_apiKey, request.Method.ToString(), url, gmtTime, _token.AccessSecret);
request.AddHeader("PolarisDate", gmtTime);
request.AddHeader("Authorization", "PWS " + _apiUser + ":" + hash);
}
示例3: Authenticate
public override void Authenticate(IRestClient client, IRestRequest request)
{
if (!string.IsNullOrWhiteSpace(AccessToken))
{
request.AddHeader("authorization", string.Format("bearer {0}", AccessToken));
}
}
示例4: PostApi
private BillingConnectorResponse PostApi(string segment, IRestRequest request)
{
try
{
log.InfoFormat("Invoking billing API on {0} with segment {1}", configuration.Url, segment);
request.AddHeader("apikey", configuration.ApiKey);
var response = client.Post(request);
if (response.StatusCode == HttpStatusCode.OK)
return new BillingConnectorResponse(true);
var failureMessage =
string.Format(
"Call to billing API return non OK status code. The status code was {0}. The response status code was {1}. The error description is {2}",
response.StatusCode, response.ResponseStatus, response.ErrorMessage);
log.ErrorFormat(failureMessage);
}
catch (Exception e)
{
log.ErrorFormat("Failed to invoke billing API on {0} because {1}", configuration.Url, e);
}
return new BillingConnectorResponse(false);
}
示例5: Authenticate
public void Authenticate(IRestClient client, IRestRequest request)
{
if (request.Parameters.All(p => !p.Name.Equals(HeaderName, StringComparison.OrdinalIgnoreCase)))
{
var value = string.Format("GoogleLogin auth={0}", _token);
request.AddHeader(HeaderName, value);
}
}
示例6: PreAuthenticate
public System.Threading.Tasks.Task PreAuthenticate(IRestClient client, IRestRequest request, System.Net.ICredentials credentials)
{
return Task.Run(() =>
{
if (!string.IsNullOrEmpty(AccessToken))
request.AddHeader("Authorization", "Bearer " + AccessToken);
});
}
示例7: AddHeaderValues
private void AddHeaderValues(IRestRequest request, IDictionary<string, string> args)
{
MapProperites(
MappingType.Header,
String.IsNullOrWhiteSpace,
args,
(name, value) => request.AddHeader(name, value));
}
示例8: PopulateHeaders
public void PopulateHeaders(ref IRestRequest request)
{
if(request == null) throw new ArgumentNullException("request", "The request must not be null!");
foreach (var header in Headers)
{
request.AddHeader(header.Name, header.Value);
}
}
示例9: Authenticate
public void Authenticate(IRestClient client, IRestRequest request)
{
if (!string.IsNullOrEmpty(AccessToken))
{
request.AddHeader("Authorization", string.Format("Bearer {0}", AccessToken));
}
request.AddParameter("app_key", AppKey);
}
示例10: Authenticate
public void Authenticate(IRestClient client, IRestRequest request)
{
if (token == null)
throw new Exception("Invalid token. Make sure to call GetAccessTokenAsync prior to your first api call.");
request.AddHeader("authorization", string.Format("{0} {1}", "Bearer"/*token.Token_type*/, token.Access_Token)).
AddHeader("trakt-api-version", 2).
AddHeader("trakt-api-key", ClientId);
}
示例11: Authenticate
public void Authenticate(IRestClient client, IRestRequest request)
{
var sb = new StringBuilder(string.Format("BoxAuth api_key={0}", _applicationApiKey));
TryAddParameter(sb, "auth_token", AccessToken);
if (Has(SharedLink))
{
TryAddParameter(sb, "shared_link", SharedLink);
}
request.AddHeader("Authorization", sb.ToString());
}
示例12: Authenticate
/// <summary>
/// Authenticates the specified client and request using Hawk authentication.
/// </summary>
/// <param name="client">The RestSharp client instance use to submit the request.</param>
/// <param name="request">The RestSharp request to execute.</param>
public void Authenticate(IRestClient client, IRestRequest request)
{
var uri = client.BuildUri(request);
var portSuffix = uri.Port != 80 ? ":" + uri.Port : "";
var host = uri.Host + portSuffix;
var method = request.Method.ToString();
var header = Hawk.GetAuthorizationHeader(host, method, uri, _credential);
request.AddHeader("Authorization", "Hawk " + header);
}
示例13: Authenticate
public void Authenticate(IRestClient client, IRestRequest request)
{
var uri = client.BuildUri(request);
var path = uri.AbsolutePath;
if( path.EndsWith("/time") && path.Length <= 8 )
{
request.AddHeader("CB-VERSION", CoinbaseConstants.ApiVersionDate);
return;
}
string timestamp = null;
if( useTimeApi )
{
var timeReq = new RestRequest("/time", Method.GET)
{
JsonSerializer = new JsonNetSerializer(jsonSettings)
};
var timeResp = client.Execute<CoinbaseResponse<Time>>(timeReq);
timestamp = timeResp.Data.Data.Epoch.ToString();
}
else
{
timestamp = GetCurrentUnixTimestampSeconds().ToString(CultureInfo.InvariantCulture);
}
var method = request.Method.ToString().ToUpper(CultureInfo.InvariantCulture);
var body = string.Empty;
var param = request.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody);
if (param != null && param?.Value?.ToString() != "null" && !string.IsNullOrWhiteSpace(param?.Value?.ToString()))
body = param.Value.ToString();
var hmacSig = GenerateSignature(timestamp, method, path, body, this.apiSecret);
request.AddHeader("CB-ACCESS-KEY", this.apiKey)
.AddHeader("CB-ACCESS-SIGN", hmacSig)
.AddHeader("CB-ACCESS-TIMESTAMP", timestamp)
.AddHeader("CB-VERSION", CoinbaseConstants.ApiVersionDate);
}
示例14: Authenticate
public override void Authenticate(IRestClient client, IRestRequest request)
{
//MXit requests that the authorize parameter is added in the following form
//Only add the Authorization header if it doesn't already exist.
if (request.Parameters.Find(
delegate(Parameter p) {
return p.Name == "Authorization";
})
== null)
{
request.AddHeader("Authorization", "Bearer " + AccessToken);
}
}
示例15: PrepareRequest
public void PrepareRequest(IRestRequest request)
{
var signature = new ApiRequestSignature { AppId = _appId };
var parameters = new[]
{
new NameValuePair(null, _appId),
new NameValuePair(null, signature.TimestampString)
};
signature.Hash = HmacUtility.GetHashString(key => new HMACSHA256(key), _secretKey, parameters);
request.AddHeader("Authorization", "HMACSHA256 " + signature);
}