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.
http redirect 302
-
- Site Admin
- Posts: 872
- Joined: Sun Jul 04, 2021 5:12 am
Re: http redirect 302
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?
Have you discussed the 403 error with whomever runs/maintains the API?
Re: http redirect 302
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?
-
- Site Admin
- Posts: 872
- Joined: Sun Jul 04, 2021 5:12 am
Re: http redirect 302
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.
-
- Site Admin
- Posts: 872
- Joined: Sun Jul 04, 2021 5:12 am
Re: http redirect 302
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):
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;
Re: http redirect 302
Ah ha yes I was just responding that I had discovered the same.. Thank you !!
Re: http redirect 302
Scott, just reporting back that the call ran successfully following updates after your change. Thanks so much!