Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using c# web api with alternate content-type

I'm new to web api and I need to create a server for a client. I have no control over the client - can't change a thing.

The client sends in an html encapsulated json request in a POST body. However, the content-type can vary. What do I need to do to allow my ApiController to process different content-types?

like image 910
user789235 Avatar asked Sep 28 '12 15:09

user789235


People also ask

What is C in used for?

C programming language is a machine-independent programming language that is mainly used to create many types of applications and operating systems such as Windows, and other complicated programs such as the Oracle database, Git, Python interpreter, and games and is considered a programming foundation in the process of ...

How do I use C on my computer?

It is a bit more cryptic in its style than some other languages, but you get beyond that fairly quickly. C is what is called a compiled language. This means that once you write your C program, you must run it through a C compiler to turn your program into an executable that the computer can run (execute).

WHAT IS &N in C?

&n writes the address of n . The address of a variable points to the value of that variable.

Why do people use C?

The biggest advantage of using C is that it forms the basis for all other programming languages. The mid-level language provides the building blocks of Python, Java, and C++. It's a fundamental programming language that will make it easier for you to learn all other programming languages.


1 Answers

Under the hood, Web Api supports Content Negotiation mechanism to automatically opt the correct formatter based on the header Content-Type in HTTP request.

By default content negotiation supports three formatters: json, xml and form-urlencoded data. If no formatter found, client will receives HTTP error 406 (Not Acceptable).

See more:

https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/content-negotiation

If you need to allow Web Api support another Content-Type, you can write your own custom formatter:

https://docs.microsoft.com/en-us/aspnet/web-api/overview/formats-and-model-binding/media-formatters

like image 136
cuongle Avatar answered Oct 09 '22 21:10

cuongle