当前位置: 首页>>代码示例>>C#>>正文


C# RestRequest.AddJsonBody方法代码示例

本文整理汇总了C#中RestSharp.Portable.RestRequest.AddJsonBody方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddJsonBody方法的具体用法?C# RestRequest.AddJsonBody怎么用?C# RestRequest.AddJsonBody使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在RestSharp.Portable.RestRequest的用法示例。


在下文中一共展示了RestRequest.AddJsonBody方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddUsuario

 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;
 }
开发者ID:paulLozano90,项目名称:RedContactos,代码行数:10,代码来源:ServicioDatos.cs

示例2: AddUsuario

        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;
        }
开发者ID:M1r3l,项目名称:RedSocialXamarin,代码行数:10,代码来源:ServicioDatos.cs

示例3: AddMensaje

        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;
        }
开发者ID:M1r3l,项目名称:RedSocialXamarin,代码行数:10,代码来源:ServicioDatos.cs

示例4: AddGrupo

        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;
        }
开发者ID:M1r3l,项目名称:TareasXamarin,代码行数:11,代码来源:Services.cs

示例5: AddTarea

        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;
        }
开发者ID:M1r3l,项目名称:TareasXamarin,代码行数:11,代码来源:Services.cs

示例6: AddContacto

        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;
        }
开发者ID:JCQuiroga,项目名称:RedContactos,代码行数:12,代码来源:ServicioDatos.cs

示例7: SubirFoto

        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;
        }
开发者ID:paulLozano90,项目名称:CamaraApp,代码行数:13,代码来源:UploadFile.cs

示例8: MainAsync

 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);
         }
     } 
 }
开发者ID:EifelMono,项目名称:RESTServer,代码行数:49,代码来源:Program.cs

示例9: loginUser

        /// <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;
        }
开发者ID:fetristan,项目名称:Audatia-Test,代码行数:20,代码来源:APIAudatia.cs

示例10: UnShim

        /// <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;
        }
开发者ID:peterson1,项目名称:ErrH,代码行数:47,代码来源:RequestShim.cs

示例11: SubirFoto

        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;
        }
开发者ID:cristajamar,项目名称:DemoCamaraXam,代码行数:20,代码来源:UploadFile.cs

示例12: UploadFichero

        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;
        }
开发者ID:FranLsz,项目名称:GestionDeTareasXamarin,代码行数:9,代码来源:ServicioDatos.cs

示例13: UpdateMensaje

 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);
 }
开发者ID:M1r3l,项目名称:RedSocialXamarin,代码行数:7,代码来源:ServicioDatos.cs

示例14: AddPostAsync

        /// <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;
                }
            }
        }
开发者ID:danielbeckmann,项目名称:DotNETJumpStart,代码行数:25,代码来源:AddPostViewModel.cs

示例15: DelContacto

 public async Task DelContacto(ContactoModel contacto)
 {
     var request = new RestRequest("Contactos")
     {
         Method = Method.DELETE
     };
     request.AddJsonBody(contacto);
     var reponse = await client.Execute(request);
 }
开发者ID:JCQuiroga,项目名称:RedContactos,代码行数:9,代码来源:ServicioDatos.cs


注:本文中的RestSharp.Portable.RestRequest.AddJsonBody方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。