Resolved PASOE 301 / 302 Redirect from the WebHandler

JamesBowen

19+ years progress programming and still learning.
I've spent the last few hours trying to figure out how to do a simple URL redirect from the PASOE WebHandler.

In the Classic WebSpeed I would do somthing like this:
Code:
<SCRIPT LANGUAGE="SpeedScript"> 
  PROCEDURE output-headers:
 
      OUTPUT-HTTP-HEADER("Status","302").
      OUTPUT-HTTP-HEADER("Location", AppURL  + "/somewebpage.html" ).
      OUTPUT-HTTP-HEADER("","").

  END PROCEDURE.

</SCRIPT>

What is the equivalent code when using the PASOE WebHandler?
 
I've figured it out. Not sure if this is the correct method, but it worked.

Code:
            DEFINE VARIABLE oResHeader   AS OpenEdge.Net.HTTP.HttpHeader NO-UNDO.
            
            oResHeader = NEW OpenEdge.Net.HTTP.HttpHeader("Location","OAuthFailure.html").
            oResponse:StatusCode = 302. //URL Redirect
            oResponse:SetHeader(oResHeader).
            //oResponse:SetHeader("location", "OAuthFailure.html" ).
 
That is indeed the right way to go.

Is there a reason you chose not to use oResponse:SetHeader("location", "OAuthFailure.html" ). ? The SetHeader method does the whole building of the HttpHeader object under the covers for you.

The other thing to make sure of is that the method returns 0.
 
That is indeed the right way to go.

Is there a reason you chose not to use oResponse:SetHeader("location", "OAuthFailure.html" ). ? The SetHeader method does the whole building of the HttpHeader object under the covers for you.

The other thing to make sure of is that the method returns 0.

This is the reason why.

1749455098535.png

SetHeader() method was only expecting one parameter.

1749455177612.png

FYI: OE 12.8.6
 
What's oResponse defined as? WebResponse has the 2-parameter SetHeader() method.
Code:
         Purpose: Default handler for the HTTP GET method. The request being
                     serviced and an optional status code is returned. A zero or
                     null value means this method will deal with all errors.                                                               
            Notes:                                                                       
    ------------------------------------------------------------------------------*/
    METHOD OVERRIDE PROTECTED INTEGER HandleGet( INPUT poRequest AS OpenEdge.Web.IWebRequest ):
    
    
        DEFINE VARIABLE oResponse        AS OpenEdge.Net.HTTP.IHttpResponse NO-UNDO.
        DEFINE VARIABLE oWriter          AS OpenEdge.Web.WebResponseWriter  NO-UNDO.
        DEFINE VARIABLE oBody            AS OpenEdge.Core.String            NO-UNDO.
 
Back
Top