question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

C# http template returns JSON / XML instead of plain text

See original GitHub issue

Not 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:closed
  • Created 7 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fabiocavcommented, Mar 30, 2016

The behavior change was probably introduced with the template update as it was changed from creating an instance of an HttpResponseMessage to use the CreateResponse 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?

0reactions
christopherandersoncommented, Apr 19, 2016

The current functionality is correct. We should honor the “Accept” header as-is.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found