Leopold Stotch
Leopold Stotch

Reputation: 1522

Web API - Return JSON object along with the HTTP Status

I have this Web API function that I wish to use to return errors if any invalid data is passed in. I do this by using the Request.CreateResponse function, and passing it the error code and list of errors.

public HttpResponseMessage Post([FromBody]Lead leadToCreate)
    {
           // Code to validate the request, and populate errorList which is a List<Error> goes here        

            if (errorList.Count > 0)
            {
                // Return list of errors and 304 code
                return Request.CreateResponse(HttpStatusCode.NotModified, errorList);
            }
            else
            {
                //Validated successfully.
                return Request.CreateResponse(HttpStatusCode.Created);
            }

   }

The Error class is:

public class Error
{
    public int number;
    public string description;
    public string url;
}

When I make a POST request with Fiddler on localhost, the error list is output as part of the JSON response (see the last line):

HTTP/1.1 304 Not Modified

Cache-Control: no-cache

Pragma: no-cache

Content-Type: application/json; charset=utf-8

Expires: -1

Server: Microsoft-IIS/10.0

X-AspNet-Version: 4.0.30319

X-SourceFiles: =?UTF-8?B?QzpcU291cmNlIENvZGVcV2ViXEZhc3R0cmFjayBBUElcRmFzdHRyYWNrIEFQSVxhcGlcc2FsZXNFbnF1aXJ5XDFc?=

X-Powered-By: ASP.NET

Date: Wed, 10 Feb 2016 14:49:20 GMT

[{"number":1,"description":"PrivateIndividual.Gender must be valid.","url":""}]

My problem is that after publishing to my live server, the error list isn't output despite using the same request data, although the correct response code is returned:

HTTP/1.1 304 Not Modified

Cache-Control: no-cache Pragma: no-cache Content-Type: application/json; charset=utf-8

Expires: -1 Server: Microsoft-IIS/7.0

X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Date: Wed, 10 Feb

2016 14:52:13 GMT Connection: close X-ScanSafe-Error: F284 Via:

HTTP/1.1 proxy10012

Can anyone see why this may be working fine on localhost, but not my live server?

Upvotes: 2

Views: 1294

Answers (1)

ovm
ovm

Reputation: 2532

It looks like there is an application layer proxy having a problem with the response:

2016 14:52:13 GMT Connection: close X-ScanSafe-Error: F284 Via:

HTTP/1.1 proxy10012

And it looks like this proxy is blocking the HttpResponse from getting back to fiddler.

Upvotes: 2

Related Questions