mardi 7 juin 2016

Web api not returning json while consuming in client

I have created a web api and i am consuming it by clinet but my web api is returning wrong format instead of JSON.

WEB API code

    public HttpResponseMessage Get()
        return base.BuildSuccessResult(HttpStatusCode.OK, todoService.GetData());

CODE for consuming web api

                        client = new HttpClient();
                        string RestUrl = "";

                        client.BaseAddress = new Uri(RestUrl);
                        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                        HttpResponseMessage response = client.GetAsync("api/TodoItems/Get").Result;
                        var content = response.Content.ReadAsStringAsync().Result;
    var uri = new Uri(string.Format(RestUrl, string.Empty));

OUTput that i am getting

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<title>Client Validation</title>
<script type="text/javascript">
function setCookie(c_name, value, expiredays) {
            document.cookie = c_name + "=" + escape(value) + ((expiredays==null) ? "" : ";expires=" + expiredays) + ";path=/";
function getHostUri() {
            var loc = document.location;
                    return loc.toString();
var exdate=new Date();
setCookie('DOAAuthReferrer', document.referrer, exdate.toUTCString());
setCookie('DOADFgsjnrSFgsg329gaFGa3ggs9434sgSGS43tsgSHSG35', '#392fc2a39a8bf6848e4f5e7551888a6d8a9db50a#FFWW#1466187439#794189797#', 'Fri, 17 Jun 2016 18:17:19 GMT');
try {  
} catch (err1) {  
    try {  
    } catch (err2) {  
        location.href = getHostUri();  
<noscript>This site requires JavaScript and Cookies to be enabled. Please change your browser settings or upgrade your browser.</noscript>

BUT i want to get json while consuming instead of above output..Please let me know what should i do???????

Aucun commentaire:

Enregistrer un commentaire