Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.clipper.visual-objects > #13496 > unrolled thread

Get dafrom API REST (method GET)

Started bySebastián BASSANO <ccyasa.sbassano@gmail.com>
First post2021-12-24 07:02 -0800
Last post2021-12-26 08:17 -0800
Articles 3 — 2 participants

Back to article view | Back to comp.lang.clipper.visual-objects


Contents

  Get dafrom API REST (method GET) Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2021-12-24 07:02 -0800
    Re: Get dafrom API REST (method GET) D.J.W. van Kooten <vankooten@removethis.ic2.com> - 2021-12-25 02:18 +0100
      Re: Get dafrom API REST (method GET) Sebastián BASSANO <ccyasa.sbassano@gmail.com> - 2021-12-26 08:17 -0800

#13496 — Get dafrom API REST (method GET)

FromSebastián BASSANO <ccyasa.sbassano@gmail.com>
Date2021-12-24 07:02 -0800
SubjectGet dafrom API REST (method GET)
Message-ID<45999a49-09a1-47fe-8305-0f1f80f536a8n@googlegroups.com>
Hi, i'm trying to consume API REST from VO.
For example:

https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD

returns

["Error de autenticaci\u00f3n (2) USER"]

but from VO i always get empty response.
I try:

Option 1
	cRequest:= "authUser=USER&authPass=PASSWORD"
	oHttpSession:= CHttp{"SENASA.APIREST"}
	IF oHttpSession:ConnectRemote("http://test.senasa.gov.ar")
		IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION)
			IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
				cResponse:= oHttpSession:GetResponse()
				InfoBox{SELF, "1.Response", cResponse}:Show()
			ELSE
				WarningBox{SELF, "1.Error.1", oHttpSession:ErrorMsg}:Show()
			ENDIF
			oHttpSession:CloseRequest()
		ELSE
			WarningBox{SELF, "1.Error.2", oHttpSession:ErrorMsg}:Show()
		ENDIF
		oHttpSession:CloseRemote()
		oHttpSession:= NULL_OBJECT
	ELSE
		WarningBox{SELF, "1.Error.3", oHttpSession:ErrorMsg}:Show()
	ENDIF

Option 2
	oHttpSession:= CHttp{"SENASA.APIREST", 443}
	IF oHttpSession:ConnectRemote("https://test.senasa.gov.ar")
		IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION + INTERNET_FLAG_SECURE)
			IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
				cResponse:= oHttpSession:GetResponse()
				InfoBox{SELF, "2.Response", cResponse}:Show()
			ELSE
				WarningBox{SELF, "2.Error.1", oHttpSession:ErrorMsg}:Show()
			ENDIF
			oHttpSession:CloseRequest()
		ELSE
			WarningBox{SELF, "2.Error.2", oHttpSession:ErrorMsg}:Show()
		ENDIF
		oHttpSession:CloseRemote()
		oHttpSession:= NULL_OBJECT
	ELSE
		WarningBox{SELF, "2.Error.3", oHttpSession:ErrorMsg}:Show()
	ENDIF

Option 3
	oHttpSession:= CHttp{"SENASA.APIREST"}
	IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
		IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION)
			IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
				cResponse:= oHttpSession:GetResponse()
				InfoBox{SELF, "3.Response", cResponse}:Show()
			ELSE
				WarningBox{SELF, "3.Error.1", oHttpSession:ErrorMsg}:Show()
			ENDIF
			oHttpSession:CloseRequest()
		ELSE
			WarningBox{SELF, "3.Error.2", oHttpSession:ErrorMsg}:Show()
		ENDIF
		oHttpSession:CloseRemote()
		oHttpSession:= NULL_OBJECT
	ELSE
		WarningBox{SELF, "3.Error.3", oHttpSession:ErrorMsg}:Show()
	ENDIF

Option 4
	oHttpSession:= CHttp{"SENASA.APIREST", 443}
	IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
		IF oHttpSession:OpenRequest("GET", "/agrotraza/src/api/Consulta_Tipo_Envase", INTERNET_FLAG_RELOAD + INTERNET_FLAG_KEEP_CONNECTION + INTERNET_FLAG_SECURE)
			IF oHttpSession:SendRequest(NULL_STRING, PTR(_CAST, cRequest), SLen(cRequest))
				cResponse:= oHttpSession:GetResponse()
				InfoBox{SELF, "4.Response", cResponse}:Show()
			ELSE
				WarningBox{SELF, "4.Error.1", oHttpSession:ErrorMsg}:Show()
			ENDIF
			oHttpSession:CloseRequest()
		ELSE
			WarningBox{SELF, "4.Error.2", oHttpSession:ErrorMsg}:Show()
		ENDIF
		oHttpSession:CloseRemote()
		oHttpSession:= NULL_OBJECT
	ELSE
		WarningBox{SELF, "4.Error.3", oHttpSession:ErrorMsg}:Show()
	ENDIF

Option 5
	oHttpSession:= CHttp{"SENASA.APIREST"}
	IF oHttpSession:ConnectRemote("http://test.senasa.gov.ar")
		cResponse:= oHttpSession:GetDocumentByURL("http://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
		InfoBox{SELF, "5.Response", cResponse}:Show()
	ELSE
		WarningBox{SELF, "5.Error.1", oHttpSession:ErrorMsg}:Show()
	ENDIF
	oHttpSession:CloseRemote()
	oHttpSession:= NULL_OBJECT

Option 6
	oHttpSession:= CHttp{"SENASA.APIREST", 443}
	IF oHttpSession:ConnectRemote("https://test.senasa.gov.ar")
		cResponse:= oHttpSession:GetDocumentByURL("https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
		InfoBox{SELF, "6.Response", cResponse}:Show()
	ELSE
		WarningBox{SELF, "6.Error.1", oHttpSession:ErrorMsg}:Show()
	ENDIF
	oHttpSession:CloseRemote()
	oHttpSession:= NULL_OBJECT

Option 7
	oHttpSession:= CHttp{"SENASA.APIREST"}
	IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
		cResponse:= oHttpSession:GetDocumentByURL("test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
		InfoBox{SELF, "7.Response", cResponse}:Show()
	ELSE
		WarningBox{SELF, "7.Error.1", oHttpSession:ErrorMsg}:Show()
	ENDIF
	oHttpSession:CloseRemote()
	oHttpSession:= NULL_OBJECT

Option 8
	oHttpSession:= CHttp{"SENASA.APIREST", 443}
	IF oHttpSession:ConnectRemote("test.senasa.gov.ar")
		cResponse:= oHttpSession:GetDocumentByURL("test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD")
		InfoBox{SELF, "8.Response", cResponse}:Show()
	ELSE
		WarningBox{SELF, "8.Error.1", oHttpSession:ErrorMsg}:Show()
	ENDIF
	oHttpSession:CloseRemote()
	oHttpSession:= NULL_OBJECT

Can any help me?
Regards.
Sebastián

[toc] | [next] | [standalone]


#13499

FromD.J.W. van Kooten <vankooten@removethis.ic2.com>
Date2021-12-25 02:18 +0100
Message-ID<ocrcsgdd1c2dhacrpkrh005tff4462i645@4ax.com>
In reply to#13496
Replying on message of Fri, 24 Dec 2021 07:02:23 -0800 (PST) from
Sebastián BASSANO:


 Hello Sebastián

>Hi, i'm trying to consume API REST from VO.
>For example:
>
>https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD
>
>returns
>
>["Error de autenticaci\u00f3n (2) USER"]
>
>but from VO i always get empty response.


We've had some trouble REST API's (Sending XML) as well, in the X#
forum I asked this question:

https://www.xsharp.eu/forum/public-product/659-rest-service-does-not-work#4634

I don't recall all details but the main problem eventually was that
from VO a user name was not used somehow and when the password was
added directly before the xml (extra key-value-pair in the POST body),
something like this, it worked:

secret=123456&xml=  <Root> etc.

Not sure if this helps you but maybe it's eventually the
authentication that fails so the result is empty. We got a test URL
which did not require a login and this returned the right values so we
knew the authentication was the problem.

If you would use an X# based DLL, which you can call from VO, you will
have more logical (.Net) code and many more samples and you will
probably solve it faster.

Dick

[toc] | [prev] | [next] | [standalone]


#13500

FromSebastián BASSANO <ccyasa.sbassano@gmail.com>
Date2021-12-26 08:17 -0800
Message-ID<aa19d248-7397-4894-a2e0-304c05f888c6n@googlegroups.com>
In reply to#13499
El Friday, December 24, 2021 a la(s) 10:18:07 PM UTC-3, D.J.W. van Kooten escribió:
> Replying on message of Fri, 24 Dec 2021 07:02:23 -0800 (PST) from 
> Sebastián BASSANO: 
> 
> 
> Hello Sebastián
> >Hi, i'm trying to consume API REST from VO. 
> >For example: 
> > 
> >https://test.senasa.gov.ar/agrotraza/src/api/Consulta_Tipo_Envase?authUser=USER&authPass=PASSWORD 
> > 
> >returns 
> > 
> >["Error de autenticaci\u00f3n (2) USER"] 
> > 
> >but from VO i always get empty response.
> We've had some trouble REST API's (Sending XML) as well, in the X# 
> forum I asked this question: 
> 
> https://www.xsharp.eu/forum/public-product/659-rest-service-does-not-work#4634 
> 
> I don't recall all details but the main problem eventually was that 
> from VO a user name was not used somehow and when the password was 
> added directly before the xml (extra key-value-pair in the POST body), 
> something like this, it worked: 
> 
> secret=123456&xml= <Root> etc. 
> 
> Not sure if this helps you but maybe it's eventually the 
> authentication that fails so the result is empty. We got a test URL 
> which did not require a login and this returned the right values so we 
> knew the authentication was the problem. 
> 
> If you would use an X# based DLL, which you can call from VO, you will 
> have more logical (.Net) code and many more samples and you will 
> probably solve it faster. 
> 
> Dick

Thanks Dick.
I'll move to C# and call the code from VO as i do in other oportunities when i got stucked with VO.

Sebastián

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.clipper.visual-objects


csiph-web