Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8517545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:43:52+00:00 2026-06-11T05:43:52+00:00

I am getting some json data posted to my asp.net webapi, but the post

  • 0

I am getting some json data posted to my asp.net webapi, but the post parameter is always coming up null – the data is not being serialized correctly. The method looks something like this:

public HttpResponseMessage Post(string id, RegistrationData registerData)

It seems the problem is that the client (which I have no control over) is always sending the content-type as x-www-form-urlencoded, even though the content is actually json. This causes mvc to try to deserialize it as form data, which fails.

Is there any way to get webapi to always deserialize as json, and to ignore the content-type header?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:43:54+00:00Added an answer on June 11, 2026 at 5:43 am

    I found the answer here: http://blog.cdeutsch.com/2012/08/force-content-types-to-json-in-net.html

    This code needs to be added to Application_Start or WebApiConfig.Register

    foreach (var mediaType in config.Formatters.FormUrlEncodedFormatter.SupportedMediaTypes) 
    {
        config.Formatters.JsonFormatter.SupportedMediaTypes.Add(mediaType);
    }
    
    config.Formatters.Remove(config.Formatters.FormUrlEncodedFormatter);
    config.Formatters.Remove(config.Formatters.XmlFormatter);
    

    It tells the json formatter to accept every type, and removes the form and xml formatters

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having some trouble getting jquery to post some json data to a rest
I am trying to handle some JSON data. But what I am getting seems
I'm trying to POST some JSON data using Adobe Flex but having some problems.
I'm having a little dilemma with an iphone project. I'm getting some JSON data
I am having trouble getting some data from a JSON object which I have
I have some problems getting the custom formated JSON data into a dijit.form.FilteringSelect. It
I'm trying to grab some JSON data from a web service using JSON.Net. The
I'm having problems deserializing some json data, getting InvalidCastExceptions and the like. Can anyone
I am just getting started with some Jackson JSON data here. This section is
I want to return some JSON data from my WebAPI controller and I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.