public AddParameter ( object value ) : void | ||
value | object | |
Résultat | void |
private async Task Authenticate() { var client = new RestClient { BaseUrl = "https://datamarket.accesscontrol.windows.net", UserAgent = UserAgent, }; var request = new RestRequest("v2/OAuth2-13", HttpMethod.Post) { ContentType = ContentTypes.FormUrlEncoded, ReturnRawString = true, }; request.AddParameter("client_id", ClientId); request.AddParameter("client_secret", ClientSecret); request.AddParameter("scope", "http://music.xboxlive.com"); request.AddParameter("grant_type", "client_credentials"); var result = await client.ExecuteAsync<string>(request); TokenResponse = JsonConvert.DeserializeObject<TokenResult>(result); if (TokenResponse != null) { TokenResponse.TimeStamp = DateTime.Now; } }
private RestRequest CreateRequest(string api, HttpMethod method, object msgBody = null) { // replace operator id var apiPath = api.Replace(OPERATOR_ID_PLACEHOLDER, operatorId); var req = new RestRequest(GetRequestUri(apiPath), method); req.ContentType = ContentTypes.Json; if (msgBody != null) { req.AddParameter(msgBody); } else { if (method == HttpMethod.Post) { req.AddParameter(new object[]{ }); } } return req; }
/// <summary> /// Acquires a new AuthToken from Azure Access Control. /// </summary> /// <returns></returns> private async Task Authenticate() { var client = new RestClient { BaseUrl = "https://datamarket.accesscontrol.windows.net", UserAgent = UserAgent, }; var request = new RestRequest("v2/OAuth2-13", HttpMethod.Post) { ContentType = ContentTypes.FormUrlEncoded, ReturnRawString = true, }; request.AddParameter("client_id", ClientId); request.AddParameter("client_secret", ClientSecret); request.AddParameter("scope", "http://music.xboxlive.com"); request.AddParameter("grant_type", "client_credentials"); var result = await client.ExecuteAsync<string>(request); TokenResponse = JsonConvert.DeserializeObject<TokenResponse>(result); if (TokenResponse != null) { TokenResponse.TimeStamp = DateTime.Now; } //var token = Regex.Match(result, ".*\"access_token\":\"(.*?)\".*", RegexOptions.IgnoreCase).Groups[1].Value; //AccessToken = token; //TokenLastAcquired = DateTime.Now; }
private async void TestWS_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e) { int i = 0; String sessionId = "zM4DQxmA7ad3OsLUFYdBTHmC69m96ilFTGazusy5"; RestClient rc = new RestClient() { BaseUrl = "http://10.37.129.2:8080" }; RestRequest req = null; RestResponse<String> ret = null; req = new RestRequest() { ContentType= ContentTypes.FormUrlEncoded, Method = HttpMethod.Post, Resource = "api/authentication" }; req.AddParameter("j_username", "admin"); req.AddParameter("j_password", "admin"); //req.AddParameter("submit", "Login"); ret = await rc.SendAsync<string>(req); i++; //req = new RestRequest() { // //ContentType= ContentTypes.FormUrlEncoded, // Method = HttpMethod.Get, // Resource = "authenticate" //}; //req.AddParameter("j_username", "admin"); //req.AddParameter("j_password", "admin"); ////req.AddParameter("remember-me", "true"); ////req.AddParameter("submit", "Login"); //req.AddParameter("Authorization", "Basic YWRtaW46YWRtaW4="); ////req.AddQueryString("j_username", "admin"); ////req.AddQueryString("j_password", "admin"); ////req.AddQueryString("remember-me", "true"); ////req.AddQueryString("submit", "Login"); //ret = await rc.SendAsync<string>(req); //foreach (String cookie in ret.HttpResponseMessage.Headers.GetValues("Set-Cookie")) //{ // if (cookie.StartsWith("JSESSIONID=")) // { // sessionId = cookie.Split(';')[0].Split('=')[1]; // } //} req = new RestRequest() { //ContentType = ContentTypes.FormUrlEncoded, Method = HttpMethod.Get, //Resource = "authenticate" Resource = "/api/events/owned" }; //req.AddHeader("Cookie", "JSESSIONID="+sessionId); //req.AddHeader("Accept", "application/json"); //req.AddParameter("JSESSIONID", sessionId); //req.AddQueryString("JSESSIONID", sessionId); RestResponse<List<EventDTO>> ret2 = await rc.SendAsync<List<EventDTO>>(req); i++; /* var client = new RestClient("http://example.com"); // client.Authenticator = new HttpBasicAuthenticator(username, password); var request = new RestRequest("resource/{id}", Method.POST); request.AddParameter("name", "value"); // adds to POST or URL querystring based on Method request.AddUrlSegment("id", "123"); // replaces matching token in request.Resource // easily add HTTP Headers request.AddHeader("header", "value"); */ }
public async Task<bool> SetAlarmModeAsync(Guid paritionUuid, string pinCode, Enums.AlarmArmMode newStatus, string secureSessionId = null, bool raiseExceptionWhenNotSuccesful = true) { if (secureSessionId == null) { var session = await InitializeSecuritySessionAsync(); if (!session.Success) throw new Exceptions.CannotEstablishSecuritySessionException(session.Error); var pinLoginResponse = await LoginAlarmWithPinAsync(session.Response.SecureSessionId, session.Response.Salt, session.Response.Nonce, pinCode); if (!pinLoginResponse.Success || !pinLoginResponse.Response.Success) throw new Exceptions.CannotSignInAlarmSystemWithPINException(pinLoginResponse.Response.Error); secureSessionId = pinLoginResponse.Response.SecureSessionId; } var alarmRequest = new AlarmRequest() { ArmMode = Enum.GetName(typeof(Enums.AlarmArmMode), newStatus), SecureSessionId = secureSessionId }; var request = new RestRequest("alarm/partitions/" + paritionUuid + "/setMode", HttpMethod.Post); request.ContentType = ContentTypes.Json; request.AddParameter(alarmRequest); var retVal = await _httpClient.SendWithPolicyAsync<AlarmRequestResponse>(this, request); if (!retVal.HttpResponseMessage.IsSuccessStatusCode) { if (raiseExceptionWhenNotSuccesful) throw new Exceptions.CannotSetAlarmStateException("Server returned: " + retVal.HttpResponseMessage.StatusCode); return false; } if (retVal.Content.Success) return true; else { if (raiseExceptionWhenNotSuccesful) throw new Exceptions.CannotSetAlarmStateException(retVal.Content.Error); return false; } }