Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

1.3K
Visualizações
Cómo POST usando el tipo de contenido HTTPclient = application/x-www-form-urlencoded

Actualmente estoy desarrollando una aplicación wp8.1 C#, logré realizar un método POST en json para mi api creando un objeto json (bm) desde textbox.texts. aquí está mi código a continuación. ¿Cómo tomo el mismo textbox.text y los PUBLICO como un content type = application/x-www-form-urlencoded ? ¿Cuál es el código para eso?

 Profile bm = new Profile(); bm.first_name = Names.Text; bm.surname = surname.Text; string json = JsonConvert.SerializeObject(bm); MessageDialog messageDialog = new MessageDialog(json);//Text should not be empty await messageDialog.ShowAsync(); HttpClient client = new HttpClient(); client.DefaultRequestHeaders.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); client.DefaultRequestHeaders.TryAddWithoutValidation("Content-Type", "application/json"); byte[] messageBytes = Encoding.UTF8.GetBytes(json); var content = new ByteArrayContent(messageBytes); content.Headers.ContentType = new MediaTypeHeaderValue("application/json"); var response = client.PostAsync("myapiurl", content).Result;
about 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

var nvc = new List<KeyValuePair<string, string>>(); nvc.Add(new KeyValuePair<string, string>("Input1", "TEST2")); nvc.Add(new KeyValuePair<string, string>("Input2", "TEST2")); var client = new HttpClient(); var req = new HttpRequestMessage(HttpMethod.Post, url) { Content = new FormUrlEncodedContent(nvc) }; var res = await client.SendAsync(req);

O

 var dict = new Dictionary<string, string>(); dict.Add("Input1", "TEST2"); dict.Add("Input2", "TEST2"); var client = new HttpClient(); var req = new HttpRequestMessage(HttpMethod.Post, url) { Content = new FormUrlEncodedContent(dict) }; var res = await client.SendAsync(req);
about 4 years ago · Santiago Trujillo Relatório

0

 var params= new Dictionary<string, string>(); var url ="Please enter URLhere"; params.Add("key1", "value1"); params.Add("key2", "value2"); using (HttpClient client = new HttpClient()) { client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.PostAsync(url, new FormUrlEncodedContent(params)).Result; var token = response.Content.ReadAsStringAsync().Result; } //Get response as expected
about 4 years ago · Santiago Trujillo Relatório

0

La mejor solución para mí es:

 // Add key/value var dict = new Dictionary<string, string>(); dict.Add("Content-Type", "application/x-www-form-urlencoded"); // Execute post method using (var response = httpClient.PostAsync(path, new FormUrlEncodedContent(dict))){}
about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda