Using mvc 4 how do you get xml back from a get request?

atpolessrop

New Member
When I visit the page with the browser it is xml but when I request the url it is json. Is there something in mvc 4 api that makes it only output json to requests through the program or can I get xml back. Note: this is happening in a desktop application and a webpage so it has to be a setting of some sort and here was the error that the desktop gave me: \[code\]Data at the root level is invalid. Line 1, position 1.\[/code\] And yes I am loading the doc right and I checked the value by using json instead and it came back ok.\[code\] private void Plus_Click(object sender, EventArgs e) { string FValue = http://stackoverflow.com/questions/11128305/id.Text; string SValue = id2.Text; string ending; string url ="http://localhost:56254/api/add?id=" + FValue + "&id2=" + SValue; XmlDocument xdoc = new XmlDocument(); xdoc.Load(url); XmlNode xNode = xdoc.SelectSingleNode("End"); ending = xNode.InnerText; Answer.Text = ending; }\[/code\]This is my desktop application code.My code it gets the xml is right here:\[code\]namespace Calculator.Controllers{ using Calculator.Models; public class AddController : ApiController { public Calcs GetAddition(int id, int id2) { double end = id + id2; Calcs[] calcs = new Calcs[] { new Calcs { FValue = http://stackoverflow.com/questions/11128305/id, SValue = id2, End = end } }; return calcs[0]; } }}\[/code\]Here is Calcs:\[code\]namespace Calculator.Models { public class Calcs { public int FValue { get; set; } public int SValue { get; set; } public double End { get; set; } } }\[/code\]Here is what the browser puts out:\[code\]<Calcs xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/Calculator.Models"><End>60</End><FValue>55</FValue><SValue>5</SValue></Calcs>\[/code\]
 
Back
Top