Openrasta xml request returned as json

I have a very simple OpenRasta application with a home resource with a single String property called Title (straight from the OpenRasta community community example).

I set up XML and JSON data contracts for this resource as follows:

ResourceSpace.Has.ResourcesOfType<Home>()
    .AtUri("/home")
    .HandledBy<HomeHandler>()
    .AsXmlDataContract()
    .And.AsJsonDataContract();

From jQuery, I can get JSON data just fine. However, when I make an Ajax jQuery XML request, I return JSON data.

My jQuery code is as follows:

$.ajax(
{
    url: "/home",
    dataType: "xml",
    success: function(result) {
        $('#xmlSpan').append($(result).find('Title').text());
    },
    error: function(request, status, ex) {
        $('#xmlSpan').append('error: ');
        $('#xmlSpan').append(status + ', ');
        $('#xmlSpan').append(ex.toString());
    }
});

The error information provided ends as follows:

error: parsererror, TypeError: a is null

But here is the interesting part. From Fiddler, my request looks like this:

GET http://127.0.0.1:51041/home HTTP/1.1
Host: 127.0.0.1:51041
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8
Accept: application/xml, text/xml, */*
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
X-Requested-With: XMLHttpRequest
Referer: http://ipv4.fiddler:51041/WebForm1.aspx
Cache-Control: max-age=0

... and my answer is as follows:

HTTP/1.1 200 OK
Server: ASP.NET Development Server/9.0.0.0
Date: Thu, 04 Mar 2010 18:30:04 GMT
X-AspNet-Version: 2.0.50727
Content-Length: 18
Cache-Control: private
Content-Type: application/json; q=0.5
Connection: Close

{"Title":"Foooo!"}

My request comes in as "Accept: application / xml", but the response is "application / json" (and the returned data is obviously json).

?

+3
1

,

(, quesiton )

, .

Accept: , /xml - (/). , OpenRasta , "- " json-.

: application/xml, text/xml; q = 0.9,/;q=0.8

. , /alltogether/

, normaly/ openrasta, . OR ?

+4

Source: https://habr.com/ru/post/1735462/


All Articles