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

628
Views
Error de tipo de medio no admitido al publicar en la API web

Estoy haciendo una aplicación de Windows Phone y, aunque puedo extraerla fácilmente de mi Web Api, tengo problemas para publicarla. Cada vez que publico en la API, recibo el mensaje de error "Tipo de medio no admitido" y no estoy seguro de por qué sucede, considerando que la clase que uso como base para mi publicación JSON es la misma que la utilizada en la API.

Publicar cotización (método de publicación)

 private async void PostQuote(object sender, RoutedEventArgs e) { Quotes postquote = new Quotes(){ QuoteId = currentcount, QuoteText = Quote_Text.Text, QuoteAuthor = Quote_Author.Text, TopicId = 1019 }; string json = JsonConvert.SerializeObject(postquote); if (Quote_Text.Text != "" && Quote_Author.Text != ""){ using (HttpClient hc = new HttpClient()) { hc.BaseAddress = new Uri("http://rippahquotes.azurewebsites.net/api/QuotesApi"); hc.DefaultRequestHeaders.Accept.Clear(); hc.DefaultRequestHeaders.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = await hc.PostAsync(hc.BaseAddress, new StringContent(json)); if (response.IsSuccessStatusCode) { Frame.Navigate(typeof(MainPage)); } else { Quote_Text.Text = response.StatusCode.ToString(); //Returning Unsupported Media Type// } } } }

Citas y Tema (Modelo)

 public class Quotes { public int QuoteId { get; set; } public int TopicId { get; set; } public string QuoteText { get; set; } public string QuoteAuthor { get; set; } public Topic Topic { get; set; } public string QuoteEffect { get; set; } } //Topic Model// public class Topic { public int TopicId { get; set; } public string TopicName { get; set; } public string TopicDescription { get; set; } public int TopicAmount { get; set; } }
over 4 years ago · Santiago Trujillo
3 answers
Answer question

0

Encontré esta pregunta mientras trabajaba en un proxy inverso rápido y sucio. Necesitaba datos de formulario y no JSON.

Esto hizo el truco para mí.

 string formData = "Data=SomeQueryString&Foo=Bar"; var result = webClient.PostAsync("http://XXX/api/XXX", new StringContent(formData, Encoding.UTF8, "application/x-www-form-urlencoded")).Result;
over 4 years ago · Santiago Trujillo Report

0

Para corregir el tipo de medio no compatible, tuve que usar HttpRequestMessage y agregar un encabezado para aceptar json con MediaTypeWithQualityHeaderValue como se muestra a continuación.

 var httpRequestMessage = new HttpRequestMessage { Content = new StringContent(json, Encoding.UTF8, "application/json") }; httpRequestMessage.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); var httpResponse = await _client.PostAsync("/contacts", httpRequestMessage.Content);
over 4 years ago · Santiago Trujillo Report

1

Debe establecer el tipo de medio al crear StringContent

 new StringContent(json, Encoding.UTF32, "application/json");
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!