Invoke a api / webservice.
Invoke a api / webservice.
How invoke a webservice from xBase / eXpress.
For example to invoke this webservice
http://www.nif.pt/?json=1&q=503949574
'503949574' is a Tax Number and the webservice returns company data.
Any sample helps.
Thanks in advance.
Respects.
Pedro Alex.
For example to invoke this webservice
http://www.nif.pt/?json=1&q=503949574
'503949574' is a Tax Number and the webservice returns company data.
Any sample helps.
Thanks in advance.
Respects.
Pedro Alex.
Pedro Alexandre
Re: Invoke a api / webservice.
Code: Select all
DC_SpawnUrl("http://www.nif.pt/?json=1&q=503949574")
The eXpress train is coming - and it has more cars.
Re: Invoke a api / webservice.
Thanks for feedBack
Invoke a webservice means to send and receive data from a website without opening the explorer.
This command opens internet explorer and shows the desired information.
But this process has to be done without opening the explorer.
Is this possible!?
Respects
Pedro Alex.
Invoke a webservice means to send and receive data from a website without opening the explorer.
This command opens internet explorer and shows the desired information.
But this process has to be done without opening the explorer.
Is this possible!?
Respects
Pedro Alex.
Pedro Alexandre
Re: Invoke a api / webservice.
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
-
- Posts: 605
- Joined: Thu Jan 28, 2010 9:11 pm
- Location: Steven Point, Wisconsin USA
- Contact:
Re: Invoke a api / webservice.
Hi Tom,
Just curious, what are the 3 lines of code.
I have used xb2.net for several things and your code example would be helpful for comparison purposes as my experience is still somewhat limited.
Cliff.
Just curious, what are the 3 lines of code.
I have used xb2.net for several things and your code example would be helpful for comparison purposes as my experience is still somewhat limited.
Cliff.
Re: Invoke a api / webservice.
LoadFromUrl() is an Alaska ASINET function.
I use it a lot to retrieve webpage info and then parse it.
This is how I use it to retrieve an Excel file from the NYC TLC website.
I use it a lot to retrieve webpage info and then parse it.
This is how I use it to retrieve an Excel file from the NYC TLC website.
Code: Select all
cUrl := "http://nyc.gov/html/tlc/downloads/excel/current_medallion_drivers.xls"
aDir := Directory(Current_Medallion_Drivers.Xls')
IF !Empty( cFileContents := GetTLCExcelFile( cUrl ) )
IF !Empty(aDir)
IF aDir[1,3] == Date()
cDate := DtoS(aDir[1,3]-1)
ELSE
cDate := DtoS(aDir[1,3])
ENDIF
FRename("Current_Medallion_Drivers.Xls", cFilePath + "\Medallion_Drivers_" + cDate + '.Xls' )
nHandle := FCreate( "Current_Medallion_Drivers.Xls" )
Fwrite( nHandle, cFileContents )
FClose( nHandle )
ENDIF
* --------------
STATIC FUNCTION GetTLCExcelFile( cUrl )
LOCAL nPort := 80, cMethod := 'GET'
RETURN SendUrl( cUrl, nPort, cMethod, {} )
* --------------
STATIC FUNCTION SendUrl( cUrl, nPort, cMethod, aVars )
LOCAL i, cString := '', cResponse, nProtocol
IF 'HTTPS:' $ Upper(cUrl)
nProtocol := INTERNET_COMMUNICATION_SECURE
nPort := INTERNET_DEFAULT_HTTPS_PORT
ELSE
nProtocol := INTERNET_COMMUNICATION_PUBLIC
nPort := INTERNET_DEFAULT_HTTP_PORT
ENDIF
IF nPort == 0
nPort := nil
ENDIF
FOR i := 1 TO Len(aVars)
IF Empty(aVars[i,1])
EXIT
ENDIF
IF i > 1
cString += '&'
ENDIF
cString += Alltrim(aVars[i,1]) + '="' + Alltrim(aVars[i,2]) + '"'
NEXT
IF cMethod == 'GET' .AND. !Empty(cString)
cUrl += '/?' + cString
cString := nil
ENDIF
cResponse := LoadFromUrl( cUrl, nPort, nProtocol, , , cMethod, cString )
IF Empty(cResponse)
cResponse := ''
ENDIF
RETURN cResponse
The eXpress train is coming - and it has more cars.
Re: Invoke a api / webservice.
Hi,
If you don't have a professional subscription, you don't have access to asinet. The loadfromurl from Phil Ide is a replacement for this.
If you don't have a professional subscription, you don't have access to asinet. The loadfromurl from Phil Ide is a replacement for this.
Re: Invoke a api / webservice.
Many thanks for your topics.
I will investigate.
Respects
Pedro Alex.
I will investigate.
Respects
Pedro Alex.
Pedro Alexandre
Re: Invoke a api / webservice.
Hi, Cliff.
Okay, eight lines.Just curious, what are the 3 lines of code.

Code: Select all
* include xb2net.ch, pragma xb2net.lib - if not already done
STATIC FUNCTION GetContent(cUrl)
LOCAL oHttp, oResponse, oForm, cContent
oHttp := xbHTTPClient():New()
oForm := xbForm():New()
oForm:SetVar( ... ) // if needed
oResponse := oHttp:Execute(cUrl,,oForm)
cContent := oResponse:Content
* destroy objects (not really needed)
RETURN cContent
Best regards,
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."
Tom
"Did I offend you?"
"No."
"Okay, give me a second chance."