C# http template returns JSON / XML instead of plain text
See original GitHub issueNot sure if this was a deliberate change, but raising it in case. Previously, HttpTriggerCSharp was returning text. Now, when I run it from portal, the response has JSON, e.g.
"Hello Azure"
What I don’t like is that if you run copy the function your and run it from new tab, you get XML, e.g.
<string xmlns="http://schemas.microsoft.com/2003/10/Serialization/">
Please pass a name on the query string or in the request body
</string>
That feels pretty heavy for what’s supposed to be the simplest template. That may be a runtime issue rather than template.
Issue Analytics
- State:
- Created 7 years ago
- Comments:6 (3 by maintainers)
Top Results From Across the Web
HTTPClient POST tries to parse a non-JSON response
If you just want to receive a plain text. You can set Http option without a header. ... By default, Angular sets the...
Read more >Format response data in ASP.NET Core Web API
For example, returning JsonResult returns JSON-formatted data and returning ContentResult returns plain-text-formatted string data.
Read more >JSON and XML Serialization in ASP.NET Web API
Describes the JSON and XML formatters in ASP.NET Web API for ASP.NET 4.x.
Read more >"content-type of the request should be text/xml " Error when ...
I have created a POST callout out to the Salesforce URL: https://login.salesforce.com/services/Soap/c/50.0 I added the SOAP raw body under ...
Read more >A beginner's guide to JSON, the data format for the internet
However, unlike XML, YAML doesn't really compete with JSON as an API data format. Instead, it's primarily used for configuration files— ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The behavior change was probably introduced with the template update as it was changed from creating an instance of an
HttpResponseMessage
to use theCreateResponse
method on the request. I do like the current behavior as it is correctly negotiating the content type, though.Regarding the default, it is already JSON, but you’re likely making the request using Chrome, and the browser is sending an accept header that includes application/xml and not application/json and since there is a registered formatter that knows how to satisfy that, it will be used.
If you try using Edge (which doesn’t include application/xml), you should get a JSON response as there will be no formatter to satisfy the accept header media types and will fallback to JSON.
I can change it so that it always use JSON in the template. But I don’t think we should change the runtime as it is behaving correctly. Thoughts?
The current functionality is correct. We should honor the “Accept” header as-is.