Midrange News for the IBM i Community


Posted by: Chris Proctor
Programmer Analyst
Columbia Sports Company
Portland, OR
Issue with apersand in a URL variable
has no ratings.
Published: 03 Aug 2016
Revised: 04 Aug 2016 - 234 days ago
Last viewed on: 26 Mar 2017 (616 views) 

Using IBM i? Need to create Excel, CSV, HTML, JSON, PDF, SPOOL reports? Learn more about the fastest and least expensive tool for the job: SQL iQuery.

Issue with apersand in a URL variable Published by: Chris Proctor on 03 Aug 2016 view comments(2)

Hello all! I'm trying to call the STRPCCMD command in my CL program, but it appears that the URL gets truncated when it hits the first apersand, missing the rest of the URL. I'm assuming there is a simple way around this issue, but I'm not sure how to code it.

If any of you have run into this issue could you please enlighten me? Here's an example of a URL that I'm trying to call. The only thing that is being sent to the browser is up to "track=yes".

call urltest ('https://wwwapps.ups.com/WebTracking/track?track=yes&trackNums=1Z0E03670312546708&loc=en_us')

Here's the simple CL code:

PGM PARM(&URL)

DCL VAR(&URL) TYPE(*CHAR) LEN(123)

DCL VAR(&URLCALL) TYPE(*CHAR) LEN(123)

 

CHGVAR VAR(&URLCALL) VALUE('start' *BCAT &URL)

STRPCO PCTA(*NO)

MONMSG MSGID(IWS4010)

STRPCCMD PCCMD(&urlcall) PAUSE(*NO)

MONMSG MSGID(CPF0000)

ENDPGM

 

Thanks!

Return to midrangenews.com home page.
Sort Ascend | Descend

COMMENTS

(Sign in to Post a Comment)
Posted by: chrisp
Premium member *
Portland, OR
Comment on: Issue with apersand in a URL variable
Posted: 7 months 21 days 21 hours 42 minutes ago

Good morning, everyone. I realize no one replied to my question and that's ok, it was a tough question, but after searching for two days I found the solution. I thought I'd share it just in case any of you ever run into the same situation. For the additional parms in the URL (requiring the ampersand) I needed to have a caret just before the ampersands. Here's the explanation I found online:

 

The problem was that the MS-DOS system uses the amersand as a special character that needs to be escaped. To escape it you must use the caret symbol Shift+6 on US keyboards. You can do this on the green screen, but
you can put it in your RPGLE code and it will compile and work properly.

cmdstring = 'STRPCCMD PCCMD(' + q + 'Start ' +
'http:' + '/' + '/' + 'example.com' +
'?parm1=' + foo + '^&parm2=' + %char(bar) + q +')
PAUSE(*NO)';

Posted by: bobcozzi
Site Admin ****
Chicagoland
Comment on: Issue with apersand in a URL variable
Posted: 7 months 21 days 19 hours 26 minutes ago

Just seeing this Chris, glad you found it, I figured it had to be escaped or encoded, but wasn't sure about the technique. Thanks!