本文整理汇总了C#中RestSharp类的典型用法代码示例。如果您正苦于以下问题:C# RestSharp类的具体用法?C# RestSharp怎么用?C# RestSharp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
RestSharp类属于命名空间,在下文中一共展示了RestSharp类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Request
public string Request(RestSharp.Method method, string endPoint, Dictionary<string,object> headers, Dictionary<string, object> parameters, Dictionary<string, object> queryParameters, string body)
{
RestClient client = new RestClient(baseURL);
RestRequest request = new RestRequest(endPoint, method);
client.Authenticator = authenticator;
foreach (var key in headers.Keys)
{
if(headers[key].GetType().ToString().StartsWith("System.Collections.Generics.List"))
{
request.AddHeader(key,JsonConvert.SerializeObject(headers[key]));
}
else
{
request.AddHeader(key,headers[key].ToString());
}
}
foreach (var key in parameters.Keys)
{
request.AddParameter(key, parameters[key]);
}
foreach (var key in queryParameters.Keys)
{
if (headers[key].GetType().ToString().StartsWith("System.Collections.Generics.List"))
{
request.AddQueryParameter(key, JsonConvert.SerializeObject(queryParameters[key]));
}
else
{
request.AddQueryParameter(key, queryParameters[key].ToString());
}
}
var response = client.Execute(request);
return response.Content;
}
开发者ID:pittNearsoft,项目名称:RestAPIClientGenerator,代码行数:34,代码来源:GenericAPICall.cs
示例2: CallApi
/// <summary>
/// Makes the HTTP request (Sync).
/// </summary>
/// <param name="path">URL path.</param>
/// <param name="method">HTTP method.</param>
/// <param name="queryParams">Query parameters.</param>
/// <param name="postBody">HTTP body (POST request).</param>
/// <param name="headerParams">Header parameters.</param>
/// <param name="formParams">Form parameters.</param>
/// <param name="fileParams">File parameters.</param>
/// <param name="authSettings">Authentication settings.</param>
/// <returns>Object</returns>
public Object CallApi(String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
Dictionary<String, FileParameter> fileParams, String[] authSettings)
{
var request = new RestRequest(path, method);
UpdateParamsForAuth(queryParams, headerParams, authSettings);
// add default header, if any
foreach(var defaultHeader in _defaultHeaderMap)
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
// add header parameter, if any
foreach(var param in headerParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(var param in queryParams)
request.AddParameter(param.Key, param.Value, ParameterType.GetOrPost);
// add form parameter, if any
foreach(var param in formParams)
request.AddParameter(param.Key, param.Value, ParameterType.GetOrPost);
// add file parameter, if any
foreach(var param in fileParams)
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
if (postBody != null) // http body (model) parameter
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
return (Object)RestClient.Execute(request);
}
开发者ID:achew22,项目名称:swagger-codegen,代码行数:47,代码来源:ApiClient.cs
示例3: CallApiAsync
public async Task<Object> CallApiAsync(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams, String[] AuthSettings) {
var request = new RestRequest(Path, Method);
UpdateParamsForAuth(QueryParams, HeaderParams, AuthSettings);
// add default header, if any
foreach(KeyValuePair<string, string> defaultHeader in this.defaultHeaderMap)
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
// add header parameter, if any
foreach(KeyValuePair<string, string> param in HeaderParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(KeyValuePair<string, string> param in QueryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(KeyValuePair<string, string> param in FormParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(KeyValuePair<string, string> param in FileParams)
request.AddFile(param.Key, param.Value);
if (PostBody != null) {
request.AddParameter("application/json", PostBody, ParameterType.RequestBody); // http body (model) parameter
}
return (Object) await restClient.ExecuteTaskAsync(request);
}
开发者ID:SYSTRAN,项目名称:nlp-api-csharp-client,代码行数:34,代码来源:ApiClient.cs
示例4: PrepareRequest
public override void PrepareRequest(RestSharp.RestRequest req)
{
req.AddParameter("clientString", _clientString, ParameterType.GetOrPost);
req.AddParameter("client_id", _clientId, ParameterType.GetOrPost);
req.AddParameter("userLogin", _username, ParameterType.GetOrPost);
req.AddParameter("password", _password, ParameterType.GetOrPost);
}
开发者ID:PearsonLearningStudio,项目名称:mobile2-windows7,代码行数:7,代码来源:FetchGrantService.cs
示例5: PrepareRequest
// Creates and sets up a RestRequest prior to a call.
private RestRequest PrepareRequest(
String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams)
{
var request = new RestRequest(path, method);
// add path parameter, if any
foreach(var param in pathParams)
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
// add header parameter, if any
foreach(var param in headerParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(var param in queryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(var param in formParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(var param in fileParams)
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
if (postBody != null) // http body (model) parameter
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
return request;
}
开发者ID:romerod,项目名称:swagger-codegen,代码行数:33,代码来源:ApiClient.cs
示例6: ToHttpResponse
public SDK.Http.IHttpResponse ToHttpResponse(RestSharp.IRestResponse response)
{
bool transportError = false;
var responseMessages = new List<string>();
transportError =
response.ResponseStatus == RestSharp.ResponseStatus.TimedOut ||
response.ResponseStatus == RestSharp.ResponseStatus.Aborted;
if (response.ErrorException != null)
{
responseMessages.Add(response.ErrorException.Message);
}
else if (!string.IsNullOrEmpty(response.ErrorMessage))
{
responseMessages.Add(response.ErrorMessage);
}
if (!string.IsNullOrEmpty(response.StatusDescription))
{
responseMessages.Add(response.StatusDescription);
}
var headers = this.ToHttpHeaders(response.Headers);
return new Impl.Http.DefaultHttpResponse(
(int)response.StatusCode,
string.Join(Environment.NewLine, responseMessages),
headers,
response.Content,
response.ContentType,
transportError);
}
开发者ID:ssankar1234,项目名称:stormpath-sdk-dotnet,代码行数:33,代码来源:RestSharpAdapter.cs
示例7: CallApi
public Object CallApi(String Path, RestSharp.Method Method, Dictionary<String, String> QueryParams, String PostBody,
Dictionary<String, String> HeaderParams, Dictionary<String, String> FormParams, Dictionary<String, String> FileParams, String[] AuthSettings) {
var response = Task.Run(async () => {
var resp = await CallApiAsync(Path, Method, QueryParams, PostBody, HeaderParams, FormParams, FileParams, AuthSettings);
return resp;
});
return response.Result;
}
开发者ID:SYSTRAN,项目名称:translation-api-csharp-client,代码行数:8,代码来源:ApiClient.cs
示例8: Authenticate
/// <summary>
/// Adds the API token key to the REST request header
/// </summary>
public void Authenticate(RestSharp.IRestClient client, RestSharp.IRestRequest request)
{
if (!request.Parameters.Any(p => p.Name.Equals("X-TOKEN", StringComparison.OrdinalIgnoreCase)))
{
var token = string.Format("{0}", _apiToken);
request.AddParameter("X-TOKEN", token, ParameterType.HttpHeader);
}
}
开发者ID:1and1,项目名称:oneandone-cloudserver-sdk-dotnet,代码行数:11,代码来源:OneAndOneAuthenticator.cs
示例9: Execute
protected RestSharp.IRestResponse Execute(string url, RestSharp.Method method, List<Header> headers)
{
if (headers == null) headers = new List<Header>();
RestSharp.IRestClient client = new RestSharp.RestClient(Root);
RestSharp.IRestRequest request = new RestSharp.RestRequest(url, method);
foreach (var header in headers)
{
request.AddParameter(header.Name, header.Value, RestSharp.ParameterType.HttpHeader);
}
request.RequestFormat = RestSharp.DataFormat.Json;
var response = client.Execute(request);
return response;
}
开发者ID:aidancasey,项目名称:Moksy,代码行数:14,代码来源:TestBase.cs
示例10: CopyHeaders
private void CopyHeaders(SDK.Http.HttpHeaders httpHeaders, RestSharp.IRestRequest restRequest)
{
if (httpHeaders == null)
{
return;
}
foreach (var header in httpHeaders)
{
foreach (var value in header.Value)
{
restRequest.AddHeader(header.Key, value);
}
}
}
开发者ID:ssankar1234,项目名称:stormpath-sdk-dotnet,代码行数:15,代码来源:RestSharpAdapter.cs
示例11: CheckException
internal bool CheckException(RestSharp.IRestResponse response)
{
if (response.ErrorException != null)
{
_log.Error(string.Format("Response error. StockID: {0}, Date: {1}", MineCar.StockID, MineCar.MiningDate), response.ErrorException);
return false;
}
else if (!response.RawBytes.Any())
{
_log.ErrorFormat("RawBytes is empty. StockID: {0}, Date: {1}", MineCar.StockID, MineCar.MiningDate);
return false;
}
return true;
}
开发者ID:pantherjain,项目名称:TwseAPIStockMiningTool,代码行数:15,代码来源:Miner.cs
示例12: Request
public RestAPIResponse Request(string endpoint, dynamic parameters = null, RestSharp.Method method = Method.GET)
{
var request = new RestRequest(endpoint, method);
RestAPIResponse result = null;
if (parameters != null) request.Parameters.AddRange(APIHelpers.ParseParameters(endpoint, parameters));
IRestResponse response = _client.Execute(request);
if(endpoint == "pull")
{
result = new PullAPIResponse() { RateLimit = APIHelpers.ParseRateLimitHeaders(response.Headers), StatusCode = response.StatusCode, PullDetails = APIHelpers.ParsePullDetailHeaders(response.Headers) };
result.Data = APIHelpers.DeserializeResponse(response.Content, ((PullAPIResponse)result).PullDetails.Format);
}
else
{
result = new RestAPIResponse() { RateLimit = APIHelpers.ParseRateLimitHeaders(response.Headers), StatusCode = response.StatusCode };
result.Data = APIHelpers.DeserializeResponse(response.Content);
}
switch((int)response.StatusCode)
{
// Ok status codes
case 200:
case 201:
case 202:
case 204:
break;
//Error status codes
case 400:
case 401:
case 403:
case 404:
case 405:
case 409:
case 413:
case 416:
case 500:
case 503:
throw new RestAPIException(result, (APIHelpers.HasAttr(result.Data, "error")) ? result.Data.error : "The request failed, please see the Data & StatusCode properties for more details.");
}
return result;
}
开发者ID:richcaudle,项目名称:datasift-dotnet,代码行数:45,代码来源:RestAPIRequest.cs
示例13: Request
private string Request(string path, RestSharp.Method method, string Data)
{
var request = new RestRequest(path, method);
request.AddParameter("text/plain", Data, ParameterType.RequestBody);
RestResponse response = Cli.Execute(request);
var code = response.StatusCode;
if(code == HttpStatusCode.Created || code == HttpStatusCode.OK || code == HttpStatusCode.NoContent)
{
return response.Content;
}
else
{
string ErrorMessage = Json.Deserialize<CoconutError> (response.Content).Message;
throw new CoconutException(ErrorMessage);
}
}
开发者ID:opencoconut,项目名称:coconutnet,代码行数:18,代码来源:CoconutAPI.cs
示例14: WarmupRequest
// This is utility function used to set Request Header and Request Parameters.
private void WarmupRequest(RestSharp.Method currentMethod,string host,string requestURL
, Dictionary<string,string> parameters, Dictionary<string,string> header)
{
restClient = new RestClient(host);
restRequest = new RestRequest(requestURL, currentMethod);
if(parameters!=null)
foreach (string paramKey in parameters.Keys)
{
restRequest.AddParameter(paramKey,parameters[paramKey]);
}
if(header!= null)
foreach (string headerKey in header.Keys)
{
restRequest.AddParameter(headerKey, parameters[headerKey]);
}
}
开发者ID:alex-bluemix,项目名称:Office-Apps-Attachment-Code-Samples,代码行数:19,代码来源:RestClient.cs
示例15: PrepareRequest
// Creates and sets up a RestRequest prior to a call.
protected virtual RestRequest PrepareRequest(
String path, RestSharp.Method method, Dictionary<String, String> queryParams, Object postBody,
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
String contentType)
{
var request = new RestRequest(path, method);
// add path parameter, if any
foreach(var param in pathParams)
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
// add header parameter, if any
foreach(var param in headerParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(var param in queryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(var param in formParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(var param in fileParams)
{
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
}
if (postBody != null) // http body (model or byte[]) parameter
{
if (postBody.GetType() == typeof(String))
{
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
}
else if (postBody.GetType() == typeof(byte[]))
{
request.AddParameter(contentType, postBody, ParameterType.RequestBody);
}
}
return request;
}
开发者ID:sameerkattel,项目名称:vc-community,代码行数:45,代码来源:ApiClient.cs
示例16: PrepareRequest
// Creates and sets up a RestRequest prior to a call.
private RestRequest PrepareRequest(
String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams, String[] authSettings)
{
var request = new RestRequest(path, method);
String epath = path;
foreach(var v in pathParams)
epath = epath.Replace("{" + v.Key + "}", v.Value);
UpdateParamsForAuth(epath, method, queryParams, headerParams, formParams, authSettings);
// add default header, if any
foreach(var defaultHeader in _defaultHeaderMap)
request.AddHeader(defaultHeader.Key, defaultHeader.Value);
// add path parameter, if any
foreach(var param in pathParams)
request.AddParameter(param.Key, param.Value, ParameterType.UrlSegment);
// add header parameter, if any
foreach(var param in headerParams)
request.AddHeader(param.Key, param.Value);
// add query parameter, if any
foreach(var param in queryParams)
request.AddQueryParameter(param.Key, param.Value);
// add form parameter, if any
foreach(var param in formParams)
request.AddParameter(param.Key, param.Value);
// add file parameter, if any
foreach(var param in fileParams)
request.AddFile(param.Value.Name, param.Value.Writer, param.Value.FileName, param.Value.ContentType);
if (postBody != null) // http body (model) parameter
request.AddParameter("application/json", postBody, ParameterType.RequestBody);
return request;
}
开发者ID:khipu,项目名称:khipu-api-dotnet-client,代码行数:43,代码来源:ApiClient.cs
示例17: Append
public static void Append(string p, RestSharp.IRestResponse response)
{
#if false
StringBuilder sb = new StringBuilder();
var request = response.Request;
if (request != null)
{
sb.Append(request.Resource);
if (request.Parameters != null && request.Parameters.Count > 0)
{
sb.Append("?");
foreach (var item in request.Parameters)
sb.AppendFormat("{0}={1}&", item.Name, item.Value);
}
}
Append(p, sb.ToString(), response.Content);
#endif
}
开发者ID:oxcsnicho,项目名称:SanzaiGuokr,代码行数:20,代码来源:DebugLogging.cs
示例18: PrepareServiceCall
public static void PrepareServiceCall(CommonQueryParameters.SignatureMethodTypes methodType,string awsAccessKeyId, string awsSecretAccessKey, out RestSharp.RestClient restClient, out RestSharp.RestRequest restRequest)
{
var signer = methodType == CommonQueryParameters.SignatureMethodTypes.HmacSHA1
? (HMAC) new HMACSHA1()
: new HMACSHA256(System.Text.Encoding.UTF8.GetBytes(awsSecretAccessKey));
var dateHeaderValue = DateTime.UtcNow.ToString("r");
var stringToSign = signer.ComputeHash(Encoding.UTF8.GetBytes(dateHeaderValue));
var requestSignature = Convert.ToBase64String(stringToSign);
var awsAuthHeaderValue = String.Format(
"AWS3-HTTPS AWSAccessKeyId={0}, Algorithm={1}, Signature={2}",
awsAccessKeyId,
methodType,
requestSignature
);
restClient = new RestSharp.RestClient("https://email.us-east-1.amazonaws.com") { FollowRedirects = true };
restRequest = new RestSharp.RestRequest(Method.POST);
restRequest.AddHeader("X-Amzn-Authorization", awsAuthHeaderValue);
restRequest.AddHeader("x-amz-date", dateHeaderValue);
}
开发者ID:simnova,项目名称:AmazonWebServices.SES,代码行数:24,代码来源:AwsService.cs
示例19: CallApi
/// <summary>
/// Makes the HTTP request (Sync).
/// </summary>
/// <param name="path">URL path.</param>
/// <param name="method">HTTP method.</param>
/// <param name="queryParams">Query parameters.</param>
/// <param name="postBody">HTTP body (POST request).</param>
/// <param name="headerParams">Header parameters.</param>
/// <param name="formParams">Form parameters.</param>
/// <param name="fileParams">File parameters.</param>
/// <param name="pathParams">Path parameters.</param>
/// <param name="contentType">Content Type of the request</param>
/// <returns>Object</returns>
public Object CallApi(
String path, RestSharp.Method method, Dictionary<String, String> queryParams, Object postBody,
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams,
String contentType)
{
var request = PrepareRequest(
path, method, queryParams, postBody, headerParams, formParams, fileParams,
pathParams, contentType);
var response = RestClient.Execute(request);
return (Object) response;
}
开发者ID:squiggle-dev,项目名称:squiggle-csharpnet45,代码行数:26,代码来源:ApiClient.cs
示例20: CallApiAsync
/// <summary>
/// Makes the asynchronous HTTP request.
/// </summary>
/// <param name="path">URL path.</param>
/// <param name="method">HTTP method.</param>
/// <param name="queryParams">Query parameters.</param>
/// <param name="postBody">HTTP body (POST request).</param>
/// <param name="headerParams">Header parameters.</param>
/// <param name="formParams">Form parameters.</param>
/// <param name="fileParams">File parameters.</param>
/// <param name="pathParams">Path parameters.</param>
/// <param name="authSettings">Authentication settings.</param>
/// <returns>The Task instance.</returns>
public async System.Threading.Tasks.Task<Object> CallApiAsync(
String path, RestSharp.Method method, Dictionary<String, String> queryParams, String postBody,
Dictionary<String, String> headerParams, Dictionary<String, String> formParams,
Dictionary<String, FileParameter> fileParams, Dictionary<String, String> pathParams, String[] authSettings)
{
var request = PrepareRequest(
path, method, queryParams, postBody, headerParams, formParams, fileParams, pathParams, authSettings);
var response = await RestClient.ExecuteTaskAsync(request);
StatusCode = (int)response.StatusCode;
ResponseHeaders = response.Headers.ToDictionary(x => x.Name, x => x.Value.ToString());
return (Object)response;
}
开发者ID:kirayhz007,项目名称:swagger-codegen,代码行数:25,代码来源:ApiClient.cs
注:本文中的RestSharp类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论