[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Ftpapi] How to retrieve http status of last request



Hi Richard,

HTTP codes 401 and 407 are intercepted by HTTPAPI and converted to the HTTPAPI error codes HTTP_NDAUTH and HTTP_PXNDAUTH, respectively.

So, you could do something like this:

if rc = -1;
   hmErrMsg = http_error(hmErrNo: hmRspCode);
   select;
   when hmErrNo = HTTP_NDAUTH;
      hmRspCode = 401;
   when hmErrNo = HTTP_PXNDAUTH;
      hmRspCode = 407;
   endsl;
endif;

Good luck


On 7/21/2020 8:48 AM, Richard la Croix wrote:
Actually http_req() didn't do what I hoped either. The Keycloak api responded with 401 and when I call it from postman returns a JSON structure with some additional info. Strangely I see no such data in the http debug log.

The return value RC from http_get ist just -1 and the response string RSP is still empty.

   001263     rc = http_req('POST'
   001264                      :%trimr(F0000F)
   001265                      :*omit
   001266                      :rsp
   001267                      :*omit
   001268                      :%trimr(F0000N)
   001269                      :%trimr(CR)
   001270                     ); 

recvresp(): entered
HTTP/1.1 401 Unauthorized
Server: nginx/1.17.8
Date: Tue, 21 Jul 2020 13:34:03 GMT
Content-Type: application/json
Content-Length: 72
Connection: keep-alive
Cache-Control: no-store
X-XSS-Protection: 1; mode=block
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15724800; includeSubDomains
X-Content-Type-Options: nosniff


SetError() #13: HTTP/1.1 401 Unauthorized
recvresp(): end with 401
recvdoc parms: identity 72
SetError() #36: This page requires a user-id & password
AuthPlugin_mustReceiceAuthErrorPage(): entered
http_close(): entered

Any suggestions are very welcome!

Regards,
Richard

Am Mo., 20. Juli 2020 um 14:34 Uhr schrieb Richard la Croix <richard.lacroix@xxxxxxxxxxx>:
Hi Jon,

thanks for the suggestion. I'll try that.

Actually HTTP_req is what I wanted to use first, but then switched to http_string for simplicity :-)

Best regards
Richard


Am Fr., 17. Juli 2020 um 19:32 Uhr schrieb Jon Paris <jon.paris@xxxxxxxxxxxxxx>:
I had exactly the same issue and the simple answer for me was to switch from http_string to http_req.  http_string is intended for ease of use but deals with errors by issuing an exception message which will not give you access to the error payload.  Sitting to http_req() allowed me to access everything I needed.

httpResponse = HTTP_req( 'POST'
                       : url
                       : *Omit
                       : response
                       : *Omit
                       : requestData
                       : 'application/json');   

   

On Jul 17, 2020, at 12:06 PM, Richard la Croix <richard.lacroix@xxxxxxxxxxx> wrote:

Hi everybody,

probably I am overlooking something, but I can't find how to retrieve the http status code of the last http request I made,

I do a http_string() with 'POST'

and after  I do:

hmErrMsg = http_error(hmErrNo: hmRspCode);

hmErrNo and hmRspCode are both 10i fields.

hmErrMsg and hmErrNo get the values that I also see in the debug log file (see below).
I understood that hmRspCode would contain the http response code, in this case 401, however the value is 0.

Also, the webservice returns a JSON structure together with the 401 which I don't receive as the result of the http_string() call. I assume HTTPAPI cancels processing after a httpStatus >= 400.

Anybody any suggestions?

Thanks in advance,
Richard


From the log file:

recvresp(): entered
HTTP/1.1 401 Unauthorized
Server: nginx/1.17.8
Date: Fri, 17 Jul 2020 15:11:31 GMT
Content-Type: application/json
Content-Length: 72
Connection: keep-alive
Cache-Control: no-store
X-XSS-Protection: 1; mode=block
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Strict-Transport-Security: max-age=15724800; includeSubDomains
X-Content-Type-Options: nosniff


SetError() #13: HTTP/1.1 401 Unauthorized
recvresp(): end with 401
recvdoc parms: identity 72
SetError() #36: This page requires a user-id & password
AuthPlugin_mustReceiceAuthErrorPage(): entered
http_close(): entered



--

--
Richard la Croix
Software Engineer

 

richard.lacroix@xxxxxxxxxxx
T +41 41 767 81 53

 

Hapimag AG | Sumpfstrasse 18
6312 Steinhausen | Schweiz
www.hapimag.com
     
Eingetragen: Handelsregister des Kantons Zug, Firmennummer/UID: CHE-101.391.790,
MWST.-Nr.: CHE-101.391.790 MWST, CEO: Hassan Kadbi



  P Please consider the environment before printing this email
 
 
--
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi

--
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi


--

--
Richard la Croix
Software Engineer

 

richard.lacroix@xxxxxxxxxxx
T +41 41 767 81 53

 

Hapimag AG | Sumpfstrasse 18
6312 Steinhausen | Schweiz
www.hapimag.com
     
Eingetragen: Handelsregister des Kantons Zug, Firmennummer/UID: CHE-101.391.790,
MWST.-Nr.: CHE-101.391.790 MWST, CEO: Hassan Kadbi



  P Please consider the environment before printing this email
 
 


--

--
Richard la Croix
Software Engineer

 

richard.lacroix@xxxxxxxxxxx
T +41 41 767 81 53

 

Hapimag AG | Sumpfstrasse 18
6312 Steinhausen | Schweiz
www.hapimag.com
     
Eingetragen: Handelsregister des Kantons Zug, Firmennummer/UID: CHE-101.391.790,
MWST.-Nr.: CHE-101.391.790 MWST, CEO: Hassan Kadbi



  P Please consider the environment before printing this email
 
 

-- 
_______________________________________________
Ftpapi mailing list
Ftpapi@xxxxxxxxxxxxxxxxxxxxxx
http://scottklement.com/mailman/listinfo/ftpapi