Subscribe for automatic updates: RSS icon RSS

Login icon Sign in for full access | Help icon Help
Advanced search

Pages: [1]
  Reply  |  Print  
Author Topic: HTTP Request and autentication  (Read 19745 times)
Marco P.
Posts: 8


« on: September 02, 2013, 11:06:37 am »

Hello,
I have an application that needs to do many http requests to the same root host. I have one example attached.

At this moment I'm able to do this, with each request that first authenticate itself an then perform the real request. The requests use all the method (GET, POST, PUT, DELETE) and each request refers to a single object of another application so it's unique.
The operation of authentication slow the entire process so I ask if there is a way to do only once at the start of entire process and use the same autentication (or connection) for all the further requests. I try to use the "keepConnections" instructions, but this seems not to work.
Do I use it in the right way?

* main.4gl (2.38 KB - downloaded 1227 times.)
Frank G.
Four Js
Posts: 48


« Reply #1 on: September 04, 2013, 11:23:06 am »

Hi,

 yes, using the req.setAuthentication() method is correct and should avoid one additional request-response step. Are your sure the login and password are correct ? Can you please set FGLWSDEBUG=3 and execute one request to see if http authentication works as expected in one single step ?

Thanks,
Frank
Marco P.
Posts: 8


« Reply #2 on: September 04, 2013, 01:02:11 pm »

Hi,
I send you 2 files:
  • 1.out: output of the program
  • fglwsdeb.txt: the results of FGLWSDEBUG
.
As you can see the first call is ok, the others are  Unauthorized

Thanks,
Marco

* log.tar.zip (3.12 KB - downloaded 1203 times.)
Frank G.
Four Js
Posts: 48


« Reply #3 on: September 04, 2013, 02:47:36 pm »

Hi,
 

  Yes, your first request passes, but all others fail because in the loop of your 4GL program, you create the HTTPRequest object again. You don't have to, as long as URL is the same. Can you please, comment line 50 and retry. It should work.
Or if URL is different, then you have to call the req.setAuthentication() method for each new created HTTPRequest object.

Please, keep me posted

Thanks,

Frank
Marco P.
Posts: 8


« Reply #4 on: September 08, 2013, 07:11:29 pm »

Ok, so you confirm what I was thinking.
I have to do many different requests so I need to call different autentication's call.

I was looking for a single connection element that is used for all request.

Thanks
Marco
Reuben B.
Four Js
Posts: 1046


« Reply #5 on: September 09, 2013, 11:45:58 pm »

Is a FormEncodedRequest a possibility.  Something like ...

Code
  1. LET req = com.HTTPRequest.Create("http://10.1.6.42/opencrx-rest-OSCRM/org.opencrx.kernel.account1/provider/CRX/segment/ITA/account")
  2. CALL req.setAuthentication(...)
  3. WHILE TRUE
  4.  -- Replace admin-ITA with variable populated differently for each request
  5.   CALL req.doFormEncodedRequest("position=0&size=1&queryType=org:opencrx:kernel:account1:Contact&query=thereExistsFullName().startsWith(\"admin-ITA\")", FALSE))
  6.   ...
  7. END WHILE

Frank: with a typical RESTful Web Service, wouldn't the base URL remain constant, and the query parameters after the ? change with each call.  Is it necessary to create a new HTTPRequest object for each call?


Reuben


Product Consultant (Asia Pacific)
Developer Relations Manager (Worldwide)
Author of https://4js.com/ask-reuben
Contributor to https://github.com/FourjsGenero
Frank G.
Four Js
Posts: 48


« Reply #6 on: September 10, 2013, 09:24:49 am »

Hi,

  Yes what you propose could work, but formEncodedRequest() is used to simulate an HTML formular submit, with some specific encoding rules. 

  Today the HTTPRequest API works per URL, so you will have to define the authentication for any new URL. I have filled a feature to allow it globally. (bz#24546)
Pages: [1]
  Reply  |  Print  
 
Jump to:  

Powered by SMF 1.1.21 | SMF © 2015, Simple Machines