What causes SS to respond with HTML as opposed to JSON?

Working on a file upload endpoint and the response is coming back as HTML instead of JSON. If I set the response ContentType = application/json it sends back a JSON object but the responseText is the HTML that would have been returned. Not sure what I’ve done differently to cause this? The DTOs are:

Request DTO

[Route("/fileReferences", "POST OPTIONS")]
public class CreateFileReferenceRequest
{
    public string Slug { get; set; }    // not used
}

Response DTO

public class IFileReferenceResponse
{
    public List<File> Files { get; set; }
}

public class FileReferenceBySlugResponse : IFileReferenceResponse
{
    public FileReference FileReference { get; set; }
}

FileReference is just a POCO.

To set the response contentType I’m using base.Response.ContentType = 'application/json';

What gets returned depends on what the Client/UserAgent/Browser says it accepts, when the Accept is not specified browsers usually ask for html.

You shouldn’t need to specify the response Content-Type in your Service as the response should automatically send back what the Client asks for. Alternative ways to request a specific Content Type is documented in Content Negotiation section in the Routing wiki. But if you did what to force ServiceStack to serialize the response with a specific content type you need to instead set:

 base.Request.ResponseContentType = MimeTypes.Json;

If your Service is still not responding as expected, check to see if it’s returning an error. You can get the error details about your service by adding ResponseStatus property to your Response DTO, e.g:

public ResponseStatus ResponseStatus { get; set; }

If it’s still an issue, please post the raw HTTP Request and Response headers, which you can get using something like Fiddler, or if this is from a browser the Network tab of Chrome WebInspector.

1 Like

Setting base.Request.ResponseContentType = MimeTypes.Json; did the trick! Thanks!