Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

1.3K
Views
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;
over 4 years ago · Santiago Trujillo
3 answers
Answer question

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);
over 4 years ago · Santiago Trujillo Report

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
over 4 years ago · Santiago Trujillo Report

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))){}
over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!