Requestbuilder post returns statuscode 404 OE 11.7

Posted by JohanBeumer on 14-Jun-2018 04:49

HI,

The following code works fine with OE 11.6.2, but fails with 11.7

De request.log points to C:\Temp\request-raw.txt which containes the following :

OpenEdge 11.7
POST /?token=AwYAAAD57FoHGPLsV4Z3UbF+HOUcwUsVYFJ+hli2hLE5NLyL2AnJD50x9eitoUyYaMLasiPCvJyKY1cmFvSi0E+xFrQSPCmDEDL0019wmJSU9aKSKjR2f6MAlNlzd8t4iutjnjM= HTTP/1.1

OpenEdge 11.6.2
POST /?token=AwYAAAD57FoHGPLsV4Z3UbF%2BHOUcwUsVYFJ%2Bhli2hLE5NLyL2AnJD50x9eitoUyYaMLasiPCvJyKY1cmFvSi0E%2BxFrQSPCmDEDL0019wmJSU9aKSKjR2f6MAlNlzd8t4iutjnjM%3D HTTP/1.1

I found https://knowledgebase.progress.com/articles/Article/URI-Encode-works-differently-in-11-7-encodes-the-equal-sign and base on that article I constructed the url as is done for variable oURI2 in the code. 

In that case both 11.6.2 and 11.7 fail the request. The query string in C:\Temp\request-raw.txt is :

POST /?token=AwYAAAD57FoHGPLsV4Z3UbF%252BHOUcwUsVYFJ%252Bhli2hLE5NLyL2AnJD50x9eitoUyYaMLasiPCvJyKY1cmFvSi0E%252BxFrQSPCmDEDL0019wmJSU9aKSKjR2f6MAlNlzd8t4iutjnjM%253D HTTP/1.1

 

Can anyone point me in the right direction to make this work for 11.7?

What am I doing wrong?

Thnx in advance!

Kind regards,
Johan Beumer

using OpenEdge.Net.*.
using OpenEdge.Net.HTTP.IHttpRequest.
using OpenEdge.Net.HTTP.IHttpResponse.
using OpenEdge.Net.HTTP.RequestBuilder.
using OpenEdge.Net.HTTP.ClientBuilder.
using OpenEdge.Core.String.

define variable oRequest     as IHttpRequest  no-undo.
define variable oRequestBody as String        no-undo.
define variable cToken       as character     no-undo.
define variable oResponse    as IHttpResponse no-undo.
define variable cChannel     as character     no-undo.
define variable oURI         as URI           no-undo.
define variable oURI2        as URI           no-undo.

session:error-stack-trace = true.
session:debug-alert = true.
log-manager:logfile-name = 'request.log'.
log-manager:logging-level = 6.
log-manager:clear-log().

cToken = "MySecretToken".
cChannel = "https://bl2p.notify.windows.com/?token=AwYAAAD57FoHGPLsV4Z3UbF%2BHOUcwUsVYFJ%2Bhli2hLE5NLyL2AnJD50x9eitoUyYaMLasiPCvJyKY1cmFvSi0E%2BxFrQSPCmDEDL0019wmJSU9aKSKjR2f6MAlNlzd8t4iutjnjM%3D".
oRequestBody = new String('<?xml version="1.0" encoding="UTF-8"?><xml version="1.0" encoding="utf-8"></xml>').

oURI = URI:Parse(cChannel).

oURI2 = OpenEdge.Net.URI:Parse(oURI:BaseURI). 
oURI2:AddQuery("token",URI:encode(oURI:GetQueryValue("token"), UriEncodingTypeEnum:default)).

oRequest = RequestBuilder:Post(oURI / oURI2, oRequestBody)
                         :ContentType("text/xml")
                         :AddHeader("X-WNS-Type", "wns/toast")
                         :AddHeader("Authorization", "Bearer " + cToken)
                         :Request.

oResponse = ClientBuilder:Build():Client:Execute(oRequest).

message oResponse:statuscode skip
        view-as alert-box information buttons ok.

Posted by JohanBeumer on 14-Jun-2018 15:00

Since you asked, I looked at the service packs and the issues that were solved with them. For 11.7.3 there has been a change for the issue I'm running into. I installed sp3 and now I got it working. Although still not the way it works in 11.6.2 but I'm satisfied!

In 11.6.2 it's enough to say :

oURI = URI:Parse(cChannel).

In 11.7 you still have to construct a new URI-object like this :

oURI = URI:Parse(cChannel).
oURI2 = OpenEdge.Net.URI:Parse(oURI:BaseURI). 
oURI2:AddQuery("token",URI:encode(oURI:GetQueryValue("token"), UriEncodingTypeEnum:default)).

Peter, thnx for asking!

Kind regards,
Johan Beumer

All Replies

Posted by Peter Judge on 14-Jun-2018 08:00
Which SP of 11.7 are you on?
Posted by JohanBeumer on 14-Jun-2018 13:00

No service pack. Should I use one?

Posted by JohanBeumer on 14-Jun-2018 15:00

Since you asked, I looked at the service packs and the issues that were solved with them. For 11.7.3 there has been a change for the issue I'm running into. I installed sp3 and now I got it working. Although still not the way it works in 11.6.2 but I'm satisfied!

In 11.6.2 it's enough to say :

oURI = URI:Parse(cChannel).

In 11.7 you still have to construct a new URI-object like this :

oURI = URI:Parse(cChannel).
oURI2 = OpenEdge.Net.URI:Parse(oURI:BaseURI). 
oURI2:AddQuery("token",URI:encode(oURI:GetQueryValue("token"), UriEncodingTypeEnum:default)).

Peter, thnx for asking!

Kind regards,
Johan Beumer

Posted by Peter Judge on 14-Jun-2018 15:18
You can save yourself some code and create the URI like below
 
oURI = new URI('https','bl2p.notify.windows.com').
oURI:AddQuery("token", 'AwYAAAD57FoHGPLsV4Z3UbF%2BHOUcwUsVYFJ%2Bhli2hLE5NLyL2AnJD50x9eitoUyYaMLasiPCvJyKY1cmFvSi0E%2BxFrQSPCmDEDL0019wmJSU9aKSKjR2f6MAlNlzd8t4iutjnjM%3D').
 
In 11.7.3 there’s also a new Parse() method that takes a second parameter to indicate whether to URL-decode the incoming string (which happens by default).  It’s this URL-Decoding on Parse() that causes the token value to get messed up.
 
Just call
oURI = OpenEdge.Net.URI:Parse(cchannel, no).
 
Method headers FYI.
 
    /** Parses a string containing a URI and creates a URI object from it
   
        @param character a string URI (eg http://www.progress.com/)
        @return URI A URI representation of the string. */
    method static public URI Parse(input pcURI as character):
        return URI:Parse(pcURI, true).
    end method.
   
    /** Parses a string containing a URI and creates a URI object from it
       
        @param character a string URI (eg http://www.progress.com/)
        @param logical TRUE if the incoming strings should be URL-decoded
        @return URI A URI representation of the string. */
    method static public URI Parse(input pcURI as character,
                                   input pDecode as logical):
 
 
 
This thread is closed