How to request webapi for a specific content type

as I understood from the ASP.NET MVC 4 Release comments is that it has a Content Consolidation and that it will return the content type requested by the client

How does a customer request specific content?

(in my case there will be a flash requesting XML using AMF)

+3


source to share


4 answers


As vansimke said, you just set the type of content you want.

In an ActionScript client, this should be as simple as:

request.setHeader("Accept", "application/xml"); 

      

The server then responds to the "Content-Type" header.



response.setHeader("Content-Type", "application/xml"); 

      

Hope it helps!

Edit: Wrong headers.

+9


source


This is only a guess, but I think the Accept header should do the trick

The request-request-header field can be used to indicate certain media types that are acceptable for the response. Accept headers can be used to indicate that the request is specifically limited to a small set of desired types, as in the case of an inline image request.



The main difference between Accept and Content-Type is that the Accept header indicates the type expected in the response when the Content-Type indicates the actual response type . Therefore, you must use Accept when requesting.

+2


source


Set the header "Content-Type:". for example Content-Type: application / xml requests xml from service.

0


source


By default web api uses json, son, you don't need to do anything to get json. You see the xml in chrome because the browser converts the response to xml. You need to use Fiddler to see the exact responses to your web service api. The web api gives you two ways to get data, json and xml, and can be changed in the response header. Use the following,

use one of these

Content-Type: application/json (for json)

      

or

Content-Type: application/xml (for xml)

      

in Fiddler go to composer and write one of these in the response header and run some tests.

0


source







All Articles