public IEnumerable<Course> Get()
{
return _courses;
}
}
public class Course
{
public int id { get; set; }
public string name { get; set; }
}
}
When i call this from index.cshtml
$(document).ready(function () {
$.getJSON("/api/values", function (data) {
var list = $('#courses');
// alert(data);
for (var i = 0; i < data.length; i++) {
var course = data[i];
list.append('<li>' + course.name + '</li>');
}
});
});
That is called chunked encoding as per headers say. that 49 means 49 bytes in the response. and 0 means no more data. it is normal Http://en.wikipedia.org/wiki/Chunked_transfer_encoding#_
SCV
Member
27 Points
23 Posts
WebApi Json return, Fiddler request-response shows wiered numbers
May 03, 2012 09:12 PM|LINK
I've just created m first WebApi project (MVC4 project, WebApi template).
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Web.Http;
namespace WebApiTry2.Controllers
{
public class ValuesController : ApiController
{
static List<Course> _courses = InitCourse();
private static List<Course> InitCourse()
{
return new List<Course> {
{new Course{id = 0, name=".net"}},
{new Course {id=1, name="oData"}},
{new Course {id=2, name="WebApi"}}
};
}
public IEnumerable<Course> Get()
{
return _courses;
}
}
public class Course
{
public int id { get; set; }
public string name { get; set; }
}
}
When i call this from index.cshtml
$(document).ready(function () {
$.getJSON("/api/values", function (data) {
var list = $('#courses');
// alert(data);
for (var i = 0; i < data.length; i++) {
var course = data[i];
list.append('<li>' + course.name + '</li>');
}
});
});
I catch that call from Fiddler
Request:
GET http://localhost:53723/api/values HTTP/1.1
Host: localhost:53723
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:11.0) Gecko/20100101 Firefox/11.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
X-Requested-With: XMLHttpRequest
Referer: http://localhost:53723/
Pragma: no-cache
Cache-Control: no-cache
Response:
HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Thu, 03 May 2012 21:00:42 GMT
X-AspNet-Version: 4.0.30319
Transfer-Encoding: chunked
Cache-Control: no-cache
Pragma: no-cache
Expires: -1
Content-Type: application/json; charset=utf-8
Connection: Close
49
[{"id":0,"name":".net"},{"id":1,"name":"oData"},{"id":2,"name":"WebApi"}]
0
Why i see 49 and 0 covered with my json return?
Shouldn't be only return
[{"id":0,"name":".net"},{"id":1,"name":"oData"},{"id":2,"name":"WebApi"}]
?
Thanks in advance!
aliostad
Member
228 Points
55 Posts
Re: WebApi Json return, Fiddler request-response shows wiered numbers
May 03, 2012 11:06 PM|LINK
SCV
Member
27 Points
23 Posts
Re: WebApi Json return, Fiddler request-response shows wiered numbers
May 04, 2012 01:05 AM|LINK
Thanks @aliostad,
Few more question on that:
Who determine that needs to pass chunked data? Client side or Server side?
I'm using ASP.Net Web Api project on web server (localhost).
And calling webapi using jquery getJson
aliostad
Member
228 Points
55 Posts
Re: WebApi Json return, Fiddler request-response shows wiered numbers
May 04, 2012 10:12 AM|LINK
It is server who determines to use the chunked encoding, although client can say it can understand it.
You do not need to worry about it. Most HTTP client implementations will handle this for you since you will not even see this in your code.
Similar to BOM in UTF8 encoding, most of the time you will not see it even when it is there.
http://en.wikipedia.org/wiki/Byte_order_mark