public async Task<UsuarioModel> AddUsuario(UsuarioModel usuario) { var request = new RestRequest("Usuario") { Method = Method.POST //Otra forma de hacerlo }; request.AddJsonBody(usuario); var response = await client.Execute<UsuarioModel>(request); return response.IsSuccess ? response.Data : null; }
public async Task<UsuarioModel> AddUsuario(UsuarioModel usuario) { var request = new RestRequest("Usuario"); request.Method = Method.POST; request.AddJsonBody(usuario); var response = await client.Execute<UsuarioModel>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<MensajeModel> AddMensaje(MensajeModel mensaje) { var request = new RestRequest("Mensaje"); request.Method = Method.POST; request.AddJsonBody(mensaje); var response = await client.Execute<MensajeModel>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<GrupoModel> AddGrupo(GrupoModel grupo) { var request=new RestRequest("Grupo"); request.Method=Method.POST; request.AddJsonBody(grupo); var response = await client.Execute<GrupoModel>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<TareaModel> AddTarea(TareaModel tarea) { var request = new RestRequest("Tarea"); request.Method = Method.POST; request.AddJsonBody(tarea); var response = await client.Execute<TareaModel>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<ContactoModel> AddContacto(ContactoModel contacto) { var request = new RestRequest("Contactos") { Method = Method.POST }; request.AddJsonBody(contacto); var reponse = await client.Execute<ContactoModel>(request); if (reponse.IsSuccess) return reponse.Data; return null; }
public async Task<String> SubirFoto(byte[] file) { var client = new RestClient(url); var request = new RestRequest(); request.Method = Method.POST; var d = new FotosModel() {Data = Convert.ToBase64String(file), idFoto = 2}; request.AddJsonBody(d); var r = await client.Execute<string>(request); return r.Data; }
async static Task MainAsync(string[] args, CancellationTokenSource cts) { using (RestClient client = new RestClient("http://localhost:4711") { Timeout = new TimeSpan(0, 0, 10) }) { while (!cts.Token.IsCancellationRequested) { if (Console.KeyAvailable) { var key = Console.ReadKey(); switch (key.KeyChar) { case 'a': { RestRequest request = new RestRequest("Hello", RestSharp.Portable.Method.POST); request.AddJsonBody(new HelloRequest { Text = "HelloText", Id = 1, }); var response = await client.Execute<HelloResponse>(request); Console.WriteLine($"Hello Response Text={response.Data.Text} Id={response.Data.Id}"); break; } case'b': { RestRequest request = new RestRequest("User/{id}", RestSharp.Portable.Method.GET); request.AddUrlSegment("id", 1); var response = await client.Execute<string>(request); Console.WriteLine($"User Response Text={Encoding.UTF8.GetString(response.RawBytes)}"); break; } case 'c': { RestRequest request = new RestRequest("User/{id}", RestSharp.Portable.Method.GET); request.AddUrlSegment("id", 666); var response = await client.Execute(request); Console.WriteLine($"User Response Text={Encoding.UTF8.GetString(response.RawBytes)}"); break; } case '\n': cts.Cancel(); return; } } else Thread.Sleep(100); } } }
/// <summary> /// Permet la connexion du joueur /// </summary> /// <param name="userNotLog">l'objet User contenant le joueur voulant se connecter</param> /// <returns></returns> public async Task<dynamic> loginUser(User userNotLog) { RestRequest request = new RestRequest("user/login", Method.POST); request.AddHeader("Content-Type", "application/json"); request.AddJsonBody(userNotLog); _client.IgnoreResponseStatusCode = true; var response = await _client.Execute<dynamic>(request); var data = Encoding.UTF8.GetString(response.RawBytes); //Permet de recuperer le message d'erreur avant que le tache se termine if (!response.IsSuccess){ throw new Exception(data); } return data; }
/// <summary> /// Converts this instance to an IRestRequest /// </summary> internal IRestRequest UnShim() { var req = new RestRequest(this.Resource, Unshim(this.Method)); if (!this.CsrfToken.IsBlank()) req.AddHeader("X-CSRF-Token", this.CsrfToken); if (this.Body != null) req.AddJsonBody(this.Body); if (this.Cookies != null) foreach (var cookie in this.Cookies) req.AddParameter(cookie.Key, cookie.Value, ParameterType.Cookie); if (this.Parameters != null) { //if (this.Parameters.Count > 0) // req.AddHeader("Content-Type", "application/x-www-form-urlencoded"); foreach (var param in this.Parameters) req.AddParameter(param.Key, param.Value, ParameterType.RequestBody); } //later: try this for attaching files to nodes: //req.ContentCollectionMode = ContentCollectionMode.MultiPartForFileParameters; //req.RequestFormat = DataFormat.Json; <--- Drupal ignores this //if (this.Attachment != null) //{ // req.AddFile(this.Attachment.Name, // this.Attachment.Stream, // this.Attachment.Name, // MediaTypeHeaderValue.Parse("multipart/form-data")); // req.AddParameter("field_name", "field_private_file");//hack: hard-code! // //req.AddParameter("files[files]", "@" + this.Attachment.Name); //} return req; }
public async Task<string> SubirFoto(byte[] file) { //Creamos el restclient var client=new RestClient(url); var request=new RestRequest(); //le decimos de que tipo es el metodo request.Method = Method.POST; //Creamos el objeto del tipo FotoModel con todos los datos del fichero var d = new FotosModel() {Datos = Convert.ToBase64String(file), Id = 2}; //el id no es necesario //Le incluimos el JSON a la variable request.AddJsonBody(d); //Y ejecutamos var r = await client.Execute<string>(request); return r.Data; }
public async Task<string> UploadFichero(FicheroModel model) { var request = new RestRequest(); request.Method = Method.POST; request.AddJsonBody(model); var r = await _client.Execute<string>(request); return r.Data; }
public async Task UpdateMensaje(MensajeModel mensaje) { var request = new RestRequest("Mensaje"); request.Method = Method.PUT; request.AddJsonBody(mensaje); var response = await client.Execute<MensajeModel>(request); }
/// <summary> /// Adds a post to the api. /// </summary> /// <param name="imageId"></param> /// <returns></returns> private async Task<bool> AddPostAsync(int imageId) { using (var client = new RestClient("http://localhost:55298/api/")) { var request = new RestRequest("posts", Method.POST); var addPost = new Post { ImageId = imageId, Title = this.title, UserIdentifier = DeviceUtils.DeviceId }; request.AddJsonBody(addPost); try { await client.Execute(request); return true; } catch { return false; } } }
public async Task DelContacto(ContactoModel contacto) { var request = new RestRequest("Contactos") { Method = Method.DELETE }; request.AddJsonBody(contacto); var reponse = await client.Execute(request); }
public async Task<bool> UpdateTarea(TareaModel model) { var request = new RestRequest("Tarea") { Method = Method.PUT }; request.AddQueryParameter("id", model.Id); request.AddJsonBody(model); try { var response = await _client.Execute(request); if (response.IsSuccess) return true; } catch (Exception ex) { var r = ex.Message; } return false; }
public async Task UpdateMensaje(MensajeModel mensaje) { var request = new RestRequest("Mensaje") { Method = Method.PUT }; request.AddJsonBody(mensaje); await client.Execute(request); }
public async Task<ContactoModel> AddContacto(ContactoModel model) { var request = new RestRequest("Contacto", Method.POST); request.AddJsonBody(model); var response = await _client.Execute<ContactoModel>(request); if (response.IsSuccess) return response.Data; return null; }
public async Task<MensajeModel> AddMensaje(MensajeModel model) { var request = new RestRequest("Mensaje", Method.POST); request.AddJsonBody(model); //request.Parameters[0].ContentType = "application/json"; //request.Parameters[0].Encoding = Encoding.UTF8; var response = await _client.Execute<MensajeModel>(request); if (response.IsSuccess) return response.Data; return null; }