本文整理汇总了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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
}
}
示例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;
}
示例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;
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
}
}
示例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);
}