BUG FOUND? REST Expose - Unable to output JSON content response (http status 401)

BUG FOUND? REST Expose - Unable to output JSON content response (http status 401)

Whats going on  here?

If you set the HTTP status code to 401 via HTTPRequestHandler.SetStatusCode Outsystems will not return your JSON response, instead it return the standard 401 response with the following html (your JSON response is never used)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/>
<title>401 - Unauthorized: Access is denied due to invalid credentials.</title>
<style type="text/css">
body{margin:0;font-size:.7em;font-family:Verdana, Arial, Helvetica, sans-serif;background:#EEEEEE;}
fieldset{padding:0 15px 10px 15px;} 
h3{font-size:1.2em;margin:10px 0 0 0;color:#000000;} 
#header{width:96%;margin:0 0 0 0;padding:6px 2% 6px 2%;font-family:"trebuchet MS", Verdana, sans-serif;color:#FFF;
#content{margin:0 0 0 2%;position:relative;}
<div id="header"><h1>Server Error</h1></div>
<div id="content">
 <div class="content-container"><fieldset>
  <h2>401 - Unauthorized: Access is denied due to invalid credentials.</h2>
  <h3>You do not have permission to view this directory or page using the credentials that you supplied.</h3>

Now, if you change the status code to something else, example http status code: 403
You will get the correct JSON response via content body.

   "Response": {
        "Success": false,
        "Timestamp": "2016-01-14T03:47:39Z",
        "Build": "1.0.0",
        "Errors": [
                "Code": "1001",
                "Type": "access_denied",
                "Message": "Error validating gateway token.",
                "Property": "GatewayToken"
        "Message": "Error validating gateway token.",
        "Language": "en-AU"
Hi Robert,

It's a known limitation caused by IIS in classic mode. IIS replaces the response content regardless of anything else. (and none of the 100+ workarounds that you will find by googling actually work correctly in IIS classic mode).
Since Integrated Mode is currently not supported by the Platform, I recommend you to stick with status code 400 even though it has a slighty different meaning.

João Rosado
joao, thanks.