Buscamos en distintos sitios para tenerte la solución para tu problema, si continúas con alguna duda déjanos tu pregunta y te respondemos con mucho gusto, porque estamos para servirte.
Ejemplo 1: c # httpclient post json stringcontent
privatestaticasyncTaskPostBasicAsync(object content,CancellationToken cancellationToken)using(var client =newHttpClient())using(var request =newHttpRequestMessage(HttpMethod.Post,Url))var json =JsonConvert.SerializeObject(content);using(var stringContent =newStringContent(json,Encoding.UTF8,"application/json"))
request.Content= stringContent;using(var response =await client
.SendAsync(request,HttpCompletionOption.ResponseHeadersRead, cancellationToken).ConfigureAwait(false))
response.EnsureSuccessStatusCode();
Ejemplo 2: httpclient post c # json
var httpClient =newHttpClient();var json =JsonConvert.SerializeObject(ticket);var content =newStringContent(json,Encoding.UTF8,"application/json");await httpClient.PostAsync("https://address.com", content);
Ejemplo 3: ejemplo HttpClient c # Post
//Base code from: http://zetcode.com/csharp/httpclient/publicasync string Example()//The data that needs to be sent. Any object works.var pocoObject =newName="John Doe",Occupation="gardener";//Converting the object to a json string. NOTE: Make sure the object doesn't contain circular references.
string json =JsonConvert.SerializeObject(pocoObject);//Needed to setup the body of the requestStringContent data =newStringContent(json,Encoding.UTF8,"application/json");//The url to post to.var url ="https://httpbin.org/post";var client =newHttpClient();//Pass in the full URL and the json string contentvar response =await client.PostAsync(url, data);//It would be better to make sure this request actually made it through
string result =await response.Content.ReadAsStringAsync();//close out the client
client.Dispose();return result;
Ejemplo 4: solicitud POST de C # HttpClient
using System;
using System.Text;
using System.Net.Http;
using System.Threading.Tasks;
using Newtonsoft.Json;
namespace HttpClientPostclassPersonpublic string Name get; set;public string Occupation get; set;public override string ToString()return $"Name: Occupation";classProgramstaticasyncTaskMain(string[] args)var person =newPerson();
person.Name="John Doe";
person.Occupation="gardener";var json =JsonConvert.SerializeObject(person);var data =newStringContent(json,Encoding.UTF8,"application/json");var url ="https://httpbin.org/post";
using var client =newHttpClient();var response =await client.PostAsync(url, data);
string result = response.Content.ReadAsStringAsync().Result;Console.WriteLine(result);
Ejemplo 5: c # .net 3.5 post json httpclient
System.Net.WebClient client =newSystem.Net.WebClient();
client.Headers.Add("content-type","application/json");//set your header here, you can add multiple headers
string s =Encoding.ASCII.GetString(client.UploadData("http://localhost:1111/Service.svc/SignIn","POST",Encoding.Default.GetBytes(""EmailId": "[email protected]","Password": "pass#123"")));
Sección de Reseñas y Valoraciones
Nos puedes añadir valor a nuestra información tributando tu experiencia en las explicaciones.
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)