本文整理汇总了C#中RestSharp.RestClient.Post方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.Post方法的具体用法?C# RestClient.Post怎么用?C# RestClient.Post使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestClient
的用法示例。
在下文中一共展示了RestClient.Post方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SignIn
public RedirectResult SignIn(string login, string password, string appId,
string redirectUri, string state)
{
var client = new RestClient(SiteConn.AuthWebApiServer);
var signInRequest = new RestRequest("Auth/SignIn");
signInRequest.AddQueryParameter("login",login);
signInRequest.AddQueryParameter("password",password);
signInRequest.AddQueryParameter("appId",appId);
signInRequest.AddQueryParameter("redirectUri", redirectUri);
signInRequest.AddQueryParameter("state","666");
var response = client.Post(signInRequest);
if (response == null) return new RedirectResult(redirectUri);
//получаю куки с токеном
if (response.Cookies != null)
{
return new RedirectResult(redirectUri);
}
return null;
}
示例2: SignIn
public RedirectResult SignIn(string login, string password, string appId,
string redirectUri, string state)
{
var client = new RestClient("http://localhost:9999/api/");
var signInRequest = new RestRequest("Auth/SignIn");
signInRequest.AddQueryParameter("login",login);
signInRequest.AddQueryParameter("password",password);
signInRequest.AddQueryParameter("appId",appId);
signInRequest.AddQueryParameter("redirectUri", redirectUri);
signInRequest.AddQueryParameter("state","666");
var response = client.Post(signInRequest);
var url = response.ResponseUri.ToString();
var urlArr = url.Split('?', '=', '&');
var user = Auth(login, password);
if (user == null)
throw new ArgumentException("Неверная пара логин/пароль");
var app = _appDataReposytory.AppDatas.FirstOrDefault(e => e.Id.ToString() == appId);
if (app == null)
throw new Exception("Нет приложения с таким appId");
_codes.Add(urlArr[2], user.Id);
//_sessionHelper.CreateNewSession(user, app);
return new RedirectResult(url);
}
示例3: Main
static void Main(string[] args)
{
var appName = string.Empty;
var hostName = string.Empty;
var help = false;
var p = new OptionSet
{
{"app=", v => appName = v},
{"host=", v => hostName = v},
{"h|?|help", v => help = v != null},
};
p.Parse(args);
if (help || string.IsNullOrWhiteSpace(appName) || string.IsNullOrWhiteSpace(hostName))
{
p.WriteOptionDescriptions(Console.Out);
return;
}
var restClient = new RestClient("http://" + hostName + ":9000");
var request = new RestRequest("/api/v1/install-queue/" + appName, Method.POST) {RequestFormat = DataFormat.Json};
request.AddBody(new { @null = string.Empty });
var response = restClient.Post(request);
if (response.StatusCode == HttpStatusCode.Created)
{
Console.WriteLine("'{0}' deployment started remotely on '{1}'.", appName, hostName);
}
}
示例4: Flush
public void Flush(Workspace workspace)
{
ConsoleEx.Info($"Running sink: {this.GetType().Name}");
var request = new RestRequest(@"api/workspaces", Method.POST);
request.AddJsonBody(workspace);
request.RequestFormat = DataFormat.Json;
var restClient = new RestClient(serviceUri);
var response = restClient.Post(request);
if(response.StatusCode == HttpStatusCode.OK)
{
ConsoleEx.Ok("Workspace analysis report published.");
var locationHeader = response.Headers.FirstOrDefault(h=> h.Name == "Location");
if (locationHeader != null)
{
string workspaceLocation = locationHeader.Value.ToString().ToLower();
ConsoleEx.Ok($"Visit {workspaceLocation}");
}
}
else
{
ConsoleEx.Error($"Workspace not published to target sink.");
ConsoleEx.Error($"Status: {response.StatusCode}, Response: {response.Content}");
}
}
示例5: Send
public void Send(OutgoingMessage outgoingMessage)
{
var client = new RestClient(TwilioBaseUrl);
client.Authenticator = new HttpBasicAuthenticator(AccountSid, AuthToken);
const string sendResource = "/SMS/Messages.json";
var request = new RestRequest(sendResource, Method.POST);
request.AddParameter("From", From);
request.AddParameter("To", outgoingMessage.To);
request.AddParameter("Body", outgoingMessage.Body);
var response = client.Post<TwilioResponse>(request);
if (response.ErrorException != null)
{
throw response.ErrorException;
}
if(response.Data.Status!="queued")
{
throw new Exception(response.Data.Message);
}
_repository.Create(new LoggedOutgoingMessage
{
Body = outgoingMessage.Body,
Sent = SystemDateTime.Now(),
ToNumber = outgoingMessage.To
});
}
示例6: Run
public IRestResponse Run(Step step, ScenarioContext context)
{
var apiPostStep = (ApiPostStep) step;
var client = new RestClient(apiPostStep.Host);
var restRequest = BuildRequest(apiPostStep);
restRequest.AddBody(apiPostStep.Payload);
return client.Post(restRequest);
}
示例7: Shorten
public string Shorten(string urlToShorten)
{
IRestClient client = new RestClient(SHORTENER_API);
IRestRequest request = new RestRequest(SHORTEN_ENDPOINT);
request.RequestFormat = DataFormat.Json;
request.AddBody(new { longUrl = urlToShorten });
IRestResponse response = client.Post(request);
dynamic json = response.Content;
return json.id ?? urlToShorten;
}
示例8: post
public static String post(String title, String content)
{
RestClient rc = new RestClient("http://app.askform.cn");
RestRequest request = new RestRequest("{guide}.aspx?Type={type}");
request.AddUrlSegment("guide", instance.FromGuide);
request.AddUrlSegment("type", instance.FormType.ToString());
request.AddParameter("Survey.F77960001-2", title);
request.AddParameter("Survey.F77960001-3", content);
request.AddParameter("Survey_duration", "0");
IRestResponse respone= rc.Post(request);
return respone.StatusCode.ToString();
}
示例9: GetAccessToken
private static AdmAccessToken GetAccessToken(string clientId, string clientSecret)
{
const string accessUri = "https://datamarket.accesscontrol.windows.net/v2/OAuth2-13";
var restClient = new RestClient(accessUri);
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "x-www-form-urlencoded");
request.AddParameter("grant_type", "client_credentials");
request.AddParameter("client_id", clientId);
request.AddParameter("client_secret", clientSecret);
request.AddParameter("scope", "http://api.microsofttranslator.com");
var token = restClient.Post<AdmAccessToken>(request);
return token.Data;
}
示例10: requestToken
/// <summary>
/// Requests a Github API token, given you received a code first, i.e. user allowed that.
///
/// See OAuth documentation for how to do that.
/// Your App needs to be registered first.
/// </summary>
/// <param name="client_id">your app's client_id</param>
/// <param name="client_secret">your app's secret</param>
/// <param name="code">code you got from github</param>
/// <returns>oauth token if successful, null otherwise</returns>
public static string requestToken(string client_id, string client_secret, string code)
{
// Not on api.github.com
var client = new RestClient("https://github.com");
client.UserAgent = "mabako/Git.hub";
var request = new RestRequest("/login/oauth/access_token");
request.RequestFormat = DataFormat.Json;
request.AddParameter("client_id", client_id);
request.AddParameter("client_secret", client_secret);
request.AddParameter("code", code);
var response = client.Post<OAuth2Data>(request);
if (response.Data != null)
return response.Data.AccessToken;
return null;
}
示例11: PhoneHome
private void PhoneHome()
{
while (true)
{
var restClient = new RestClient("http://localhost:9001") {Timeout = 1000};
var request = new RestRequest("/api/v1/clients/register", Method.POST) {RequestFormat = DataFormat.Json};
request.AddBody(new { @null = string.Empty });
restClient.Post(request);
if (_cancellation.IsCancellationRequested)
{
break;
}
Thread.Sleep(new TimeSpan(0,0,0, 30));
}
}
示例12: send
public void send(string recipient, string text)
{
if (string.IsNullOrEmpty(text) || text.Length > 603)
{
_log.Error("Unable to send sms because text is null or longer than 603 characters.");
return;
}
if (string.IsNullOrEmpty(recipient) || !_numberValidator.IsMatch(recipient))
{
_log.Error("Unable to send sms because recipient isn't a valid phone number.");
return;
}
if (string.IsNullOrEmpty(_username) || string.IsNullOrEmpty(_password))
{
_log.Error("Unable to send sms because 'sms.username' or 'sms.password' is not specified.");
return;
}
var client = new RestClient("https://json.aspsms.com");
var request = new RestRequest("SendSimpleTextSMS");
request.AddJsonBody(new
{
UserName = _username,
Password = _password,
Originator = "Xpressive.H",
Recipients = new [] { recipient },
MessageText = text
});
var response = client.Post(request);
if (response.StatusCode != HttpStatusCode.OK && response.ErrorMessage != null)
{
if (response.ErrorException != null)
{
_log.Error("Error when sending SMS: " + response.ErrorMessage, response.ErrorException);
}
else
{
_log.Error("Error when sending SMS: " + response.ErrorMessage);
}
}
}
开发者ID:xpressive-websolutions,项目名称:Xpressive.Home.ProofOfConcept,代码行数:45,代码来源:SmsScriptObjectProvider.cs
示例13: AddMan
public RedirectToRouteResult AddMan(Manufacturer man)
{
var token = _sessionHelper.GetToken();
if (token == "SessionIsNull")
return RedirectToAction("GoToErrorForm", "Cpu");
var clientMan = new RestClient(SiteConn.ManWebApiServer);
var addMan = new RestRequest($"Man/AddMan", Method.POST)
{
RequestFormat = DataFormat.Json
};
addMan.AddHeader("Authorization", token);
addMan.AddHeader("Content-Type", "application/json");
addMan.AddObject(man);
var responseMan = clientMan.Post(addMan);
return RedirectToAction("List", "Man");
}
示例14: Register
//private readonly string serviceUri = "http://localhost:5000";
public Registration Register(string emailAddress)
{
var serviceClient = new RestClient(serviceUri);
var request = new RestRequest(@"api/accounts", Method.POST);
request.AddJsonBody(new
{
email = emailAddress
});
request.RequestFormat = DataFormat.Json;
var response = serviceClient.Post<Registration>(request);
if (response.StatusCode == HttpStatusCode.OK)
{
return response.Data;
}
else
{
ConsoleEx.Error($"Registration failed.");
ConsoleEx.Error($"Status: {response.StatusCode}, Response: {response.Content}");
return null;
}
}
示例15: HttpPost
public static string HttpPost(this Uri uri, IDictionary<string, string> parameters)
{
RestClient client = new RestClient(uri.GetBaseUrl());
RestRequest request = new RestRequest();
if (parameters != null)
{
foreach (KeyValuePair<string, string> pair in parameters)
{
request.AddParameter(pair.Key, pair.Value);
}
}
IRestResponse response = client.Post(request);
response.CheckResponse();
return response.Content;
}