http redirect 302

Discussions related to HTTPAPI (An HTTP Client Package for RPG programming.) http://www.scottklement.com/httpapi/
Post Reply
davidb
Posts: 9
Joined: Tue May 31, 2022 3:48 pm

http redirect 302

Post by davidb »

Hello, I'm executing http_url_get to the us treasury to obtain their SDN list at the following address:

https://sanctionslistservice.ofac.treas ... rts/SDN.FF

Last week they changed their internal process to use a redirect to an Amazon server. As a result of their change, I'm now getting an error 302.

I've added code to trap the 302 error and re-post to the address returned by http_redir_loc, in line with Scott's directions in other posts. The call appears to be landing correctly, but now now I get a 403 error.

Here's the code:

URL is defined as a 2048 alpha.

URL= 'https://sanctionslistservice.ofac.treas ... rts/SDN.FF';
IFS = '/TEST/SDN.FF';

rc = http_url_get(URL:IFS);

if (rc=302);
URL=http_redir_loc;
rc = http_url_get( URL:IFS);
endif;

if (rc <> 1);
Msg = http_error;
....

Any help appreciated.
Scott Klement
Site Admin
Posts: 674
Joined: Sun Jul 04, 2021 5:12 am

Re: http redirect 302

Post by Scott Klement »

403 means you don't have access to the URL you requested. Perhaps you need to log in first?

Have you discussed the 403 error with whomever runs/maintains the API?
davidb
Posts: 9
Joined: Tue May 31, 2022 3:48 pm

Re: http redirect 302

Post by davidb »

No I haven't disclosed it (the 403). If I run a 'get' in SOAPUI to the same origin address, the redirect is tripped automatically. I get the file I'm supposed to get without adding any additional auth (that I don't have) or taking any additional action. Why would that be working vs the call I'm making to the redirected address?
Scott Klement
Site Admin
Posts: 674
Joined: Sun Jul 04, 2021 5:12 am

Re: http redirect 302

Post by Scott Klement »

HTTPAPI does not automaticlaly redirect, you have to code it... I don't know why you'd get a 403 error with HTTPAPI and not with SoapUI, though. I don't see anything obvious wrong with your code -- but I am not familiar with this API.
Scott Klement
Site Admin
Posts: 674
Joined: Sun Jul 04, 2021 5:12 am

Re: http redirect 302

Post by Scott Klement »

I tried it myself, and the redirect URL is longer than the 1024 that HTTPAPI allows for a redirect URL.

So I made http_redir_loc() return a longer string... you can get the updated code here:
https://www.scottklement.com/httpapi/

Once you've updated to 1.51, recompile your program and try again.

This is the code I used (it worked, but could use more error checking/handling):

Code: Select all

**free
ctl-opt dftactgrp(*no) actgrp(*new) bnddir('HTTPAPI');

 /copy HTTPAPI_H

dcl-s rc int(10);
dcl-s url varchar(2048);
dcl-s stmf varchar(256); 

http_debug(*on: '/tmp/sdn.log');

url = 'https://sanctionslistservice.ofac.treas.gov/api/+
              PublicationPreview/exports/SDN.FF';
stmf = '/tmp/sdn.ff';

rc = http_req('GET': url: stmf: *omit);
dow rc in %list(301:302:303:307:308);
  url = http_redir_loc();
  rc = http_req('GET': url: stmf: *omit);
enddo;

if rc <> 1;
  http_crash();
endif;

*inlr = *on;
davidb
Posts: 9
Joined: Tue May 31, 2022 3:48 pm

Re: http redirect 302

Post by davidb »

Ah ha yes I was just responding that I had discovered the same.. Thank you !!
davidb
Posts: 9
Joined: Tue May 31, 2022 3:48 pm

Re: http redirect 302

Post by davidb »

Scott, just reporting back that the call ran successfully following updates after your change. Thanks so much!
Post Reply