本文整理汇总了C#中RestSharp.RestRequest.AddBody方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddBody方法的具体用法?C# RestRequest.AddBody怎么用?C# RestRequest.AddBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestRequest
的用法示例。
在下文中一共展示了RestRequest.AddBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ListCreate
/// <summary>
/// Creates a new list for the user associated with the current session
/// </summary>
/// <param name="name">The name of the new list</param>
/// <param name="description">Optional description for the list</param>
/// <param name="language">Optional language that might indicate the language of the content in the list</param>
/// <remarks>Requires a valid user session</remarks>
/// <exception cref="UserSessionRequiredException">Thrown when the current client object doens't have a user session assigned.</exception>
public async Task<string> ListCreate(string name, string description = "", string language = null)
{
RequireSessionId(SessionType.UserSession);
if (string.IsNullOrWhiteSpace(name))
throw new ArgumentNullException("name");
// Description is expected by the API and can not be null
if (string.IsNullOrWhiteSpace(description))
description = "";
RestRequest request = new RestRequest("list") { RequestFormat = DataFormat.Json };
AddSessionId(request, SessionType.UserSession);
language = language ?? DefaultLanguage;
if (!String.IsNullOrWhiteSpace(language))
{
request.AddBody(new { name = name, description = description, language = language });
}
else
{
request.AddBody(new { name = name, description = description });
}
IRestResponse<ListCreateReply> response = await _client.ExecutePostTaskAsync<ListCreateReply>(request).ConfigureAwait(false);
return response.Data == null ? null : response.Data.ListId;
}
示例2: Get
internal static RestRequest Get(Type type, ContractObject restObj)
{
restObj.type = restObj.Type;
var request = new RestRequest
{
RequestFormat = DataFormat.Json
};
switch (type)
{
case Type.Get:
request.Method = Method.GET;
request.Resource = restObj.Uri + "/" + restObj.id + "?depth=" + restObj.depth;
break;
case Type.Put:
request.Method = Method.PUT;
request.Resource = restObj.Uri + "/" + restObj.id;
request.AddBody(restObj);
break;
case Type.Post:
request.Method = Method.POST;
request.Resource = restObj.Uri;
request.AddBody(restObj);
break;
case Type.Delete:
request.Method = Method.DELETE;
request.Resource = restObj.Uri + "/" + restObj.id;
break;
case Type.Search:
request.Method = Method.GET;
var resource = new StringBuilder(100);
resource.Append(restObj.Uri);
resource.Append("s"); // pluralize the endpoint
var searchObj = restObj as ISearchable;
resource.Append("?search=" + searchObj.searchTerm +
"&count=" + searchObj.pageSize +
"&page=" + searchObj.page
);
request.Resource = resource.ToString();
break;
default:
throw new NotSupportedException(type.ToString());
}
return request;
}
示例3: SetPriorities
/// <summary>
/// Changes the priority of a list of issues on a given priority ID
/// </summary>
/// <param name="IssueKeys"></param>
/// <param name="PriorityId"></param>
/// <param name="waiter"></param>
/// <param name="eventHandler"></param>
public static void SetPriorities(List<string> IssueKeys, string PriorityId,
EventHandler<ResponseArg> eventHandler)
{
List<RestRequest> requests = new List<RestRequest>();
foreach (var issueKey in IssueKeys)
{
var request = new RestRequest("issue/" + issueKey, Method.PUT);
request.AddHeader("Content-Type", "application/json");
request.RequestFormat = RestSharp.DataFormat.Json;
var newissue =
new
{
fields = new
{
priority = new
{
id = PriorityId
}
}
};
request.AddBody(newissue);
requests.Add(request);
}
BackgroundJira bj = new BackgroundJira();
bj.WorkerComplete += eventHandler;
bj.Start<Priority>(requests);
}
示例4: SendScreenshot
public void SendScreenshot(Guid screenshotId, string macAddress, Guid requestId)
{
if (base64Image == null)
{
Logger.Instance.Write("SendScreenshot", LogLevel.Medium, "No screenshot taken.");
return;
}
var request = new RestRequest("v1/signboards/{macAddress}/screenshots", Method.POST);
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddUrlSegment("macAddress", macAddress);
request.AddBody(ScreenshotModel.From(screenshotId, base64Image));
var response = Client.Execute(request);
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
Logger.Instance.Write("SendScreenshot", LogLevel.Medium, "Screenshot request successfull");
RequestComponent.GetInstance().FinishRequest(macAddress, RequestInputModel.From(requestId, true));
return;
}
else
{
Logger.Instance.Write("SendScreenshot", LogLevel.Medium, "Screenshot request failed. " + ((response != null && response.ErrorMessage != null ) ? response.ErrorMessage.ToString() : " Response object is null"));
RequestComponent.GetInstance().FinishRequest(macAddress, RequestInputModel.From(requestId, false));
return;
}
}
示例5: PutLicenseTags
public IRestResponse PutLicenseTags( string licenseTagsAssignmentHref, IEnumerable<LicenseTag> tags )
{
var request = new RestRequest( licenseTagsAssignmentHref, Method.PUT );
request.RequestFormat = DataFormat.Json;
request.AddBody( tags );
return Execute( request );
}
示例6: PostMessage
public ActionResult PostMessage(string webHookUrl)
{
var client = new RestClient(webHookUrl);
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.RequestFormat = DataFormat.Json;
request.AddBody(new
{
title = "Outlook Custom Connector Webhooks Demo",
text = "Message posted from my ASP.NET MVC Appplication",
themeColor = "DB4C3F"
});
var response = client.Execute(request);
var content = response.Content;
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
return View("Success");
}
else
{
return View();
}
}
示例7: Create
public ActionResult Create(SetGameDTO createGame)
{
if (!Session["Role"].Equals("Admin"))
{
return RedirectToAction("Index", "Home");
}
var request = new RestRequest("api/Games", Method.POST);
var apiKey = Session["ApiKey"];
var UserId = Session["UserId"];
request.AddHeader("xcmps383authenticationkey", apiKey.ToString());
request.AddHeader("xcmps383authenticationid", UserId.ToString());
request.RequestFormat = DataFormat.Json;
request.AddBody(createGame);
var queryResult = client.Execute(request);
statusCodeCheck(queryResult);
var redirectUrl = new UrlHelper(Request.RequestContext).Action("Create", "Game");
if (queryResult.StatusCode != HttpStatusCode.Created)
{
redirectUrl = new UrlHelper(Request.RequestContext).Action("Create", "Game");
return Json(new { Url = redirectUrl });
}
else if (queryResult.StatusCode == HttpStatusCode.Forbidden)
{
redirectUrl = new UrlHelper(Request.RequestContext).Action("Login", "User");
return Json(new { Url = redirectUrl });
}
redirectUrl = new UrlHelper(Request.RequestContext).Action("Index", "Game");
return Json(new { Url = redirectUrl });
}
示例8: LogOut
public static void LogOut(User user)
{
RestClient client = new RestClient(ConfigurationManager.AppSettings["endpoint"]);
RestRequest request = new RestRequest("Users/Login", Method.POST);
request.AddBody(user);
var response = client.Execute(request) as RestResponse;
}
示例9: CheckConnectivity
public bool CheckConnectivity()
{
bool connected = true;
try
{
var request = new RestRequest("query", Method.POST);
request.RequestFormat = DataFormat.Json;
//request.RequestBody
request.AddBody(new { txtQuery = "f2a0341b3" });
var response = this._client.Execute(request);
Console.WriteLine(response.Content);
connected = true;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
connected = false;
}
return connected;
}
示例10: Invoke
public string Invoke(string method, string action, object message)
{
Method m;
Method.TryParse(method, true, out m);
var client = new RestClient(ApiUrl);
var request = new RestRequest(action, m) { RequestFormat = DataFormat.Json };
if (message != null)
request.AddBody(message);
request.AddHeader("apikey", ApiKey);
var response = client.Execute(request);
if (response.StatusCode != HttpStatusCode.OK)
throw new Exception("Api call failed: " + response.StatusDescription);
logger.InfoFormat("{0} invoked successfully",ApiUrl + action);
if (response.Headers.Any(h => h.Name == "watchr.commandsavailable"))
Bus.SendLocal(new FetchCommands());
return response.Content;
}
示例11: CreateCampaign
/// <summary>
/// Limited to campaigns containing emails and segments
/// </summary>
public Campaign CreateCampaign(int emailId, int segmentId)
{
CampaignEmail campaignEmail = _elementHelper.GetCampaignEmail(emailId, -101);
CampaignSegment campaignSegment = _elementHelper.GetCampaignSegment(segmentId, -100, -101);
Campaign campaign = new Campaign
{
name = "sample campaign",
campaignType = "sample",
type = "Campaign",
startAt = ConvertToUnixEpoch(DateTime.Now),
endAt = ConvertToUnixEpoch(DateTime.Today.AddDays(1)),
elements = new List<CampaignElement>
{
campaignSegment,
campaignEmail
}
};
RestRequest request = new RestRequest(Method.POST)
{
Resource = "/assets/campaign",
RequestFormat = DataFormat.Json
};
request.AddBody(campaign);
IRestResponse<Campaign> response = _client.Execute<Campaign>(request);
return response.Data;
}
示例12: CreateLoadBalancer
/// <summary>
/// Adds a new load balancer to the IP
/// </summary>
/// <param name="server_id">Unique server's identifier.</param>
/// <param name="ip_id">Unique server's identifier.</param>
public ServerResponse CreateLoadBalancer(string server_id, string ip_id, string loadBalancerId)
{
try
{
var request = new RestRequest("/servers/{server_id}/ips/{ip_id}/load_balancers", Method.POST)
{
RequestFormat = DataFormat.Json,
JsonSerializer = new CustomSerializer()
};
request.AddUrlSegment("server_id", server_id);
request.AddUrlSegment("ip_id", ip_id);
string load_balancer_id = loadBalancerId;
request.AddBody(new { load_balancer_id });
var result = restclient.Execute<ServerResponse>(request);
if (result.StatusCode != HttpStatusCode.Accepted)
{
throw new Exception(result.Content);
}
return result.Data;
}
catch
{
throw;
}
}
示例13: RequestFriend
public void RequestFriend(string username, Action<string> onCompleted)
{
var friendRequest = new InitialFriendRequest { username = username };
var friendRequestRootObject = new InitialFriendRequestRoot { friend_request = friendRequest };
var request = new RestRequest(Method.POST);
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddBody(friendRequestRootObject);
var friendsRequestApiCall = _pgSession.GetWebAppFunction("/api", "/friend_requests");
var client = new RestClient(friendsRequestApiCall);
_pgSession.Begin(delegate
{
var apiResponse = (RestResponse<ApiResponse>)client.Execute<ApiResponse>(request);
if (!apiResponse.IsOk())
{
onCompleted(apiResponse.Data.message);
}
else
{
onCompleted(null);
}
});
}
示例14: Build
public IRestRequest Build()
{
var request = new RestRequest(methodInfo.Path, methodInfo.Method);
request.RequestFormat = DataFormat.Json; // TODO: Allow XML requests?
for (int i = 0; i < arguments.Count(); i++)
{
Object argument = arguments[i];
var usage = methodInfo.ParameterUsage[i];
switch (usage)
{
case RestMethodInfo.ParamUsage.Query:
request.AddParameter(methodInfo.ParameterNames[i], argument);
break;
case RestMethodInfo.ParamUsage.Path:
request.AddUrlSegment(methodInfo.ParameterNames[i], argument.ToString());
break;
case RestMethodInfo.ParamUsage.Body:
request.AddBody(argument);
break;
default:
throw new ArgumentOutOfRangeException();
}
}
return request;
}
示例15: CreateCustomer
internal IRestResponse CreateCustomer( CustomerSummary customer )
{
var request = new RestRequest( GetApiPrefix( ApiType.Consume ) + "/customer", Method.POST );
request.RequestFormat = DataFormat.Json;
request.AddBody( customer );
return Execute( request );
}