Invoke a api / webservice.

This forum is for eXpress++ general support.
Post Reply
Message
Author
User avatar
PedroAlex
Posts: 231
Joined: Tue Feb 09, 2010 3:06 am

Invoke a api / webservice.

#1 Post by PedroAlex »

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.
Pedro Alexandre

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Invoke a api / webservice.

#2 Post by rdonnay »

Code: Select all

DC_SpawnUrl("http://www.nif.pt/?json=1&q=503949574")
The eXpress train is coming - and it has more cars.

User avatar
PedroAlex
Posts: 231
Joined: Tue Feb 09, 2010 3:06 am

Re: Invoke a api / webservice.

#3 Post by PedroAlex »

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.
Pedro Alexandre

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Invoke a api / webservice.

#4 Post by skiman »

Best regards,

Chris.
www.aboservice.be

User avatar
Tom
Posts: 1173
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Invoke a api / webservice.

#5 Post by Tom »

3 lines of code with Boris Borzic's Xb2.Net.

http://www.xb2.net/menu.htm
Best regards,
Tom

"Did I offend you?"
"No."
"Okay, give me a second chance."

Cliff Wiernik
Posts: 605
Joined: Thu Jan 28, 2010 9:11 pm
Location: Steven Point, Wisconsin USA
Contact:

Re: Invoke a api / webservice.

#6 Post by Cliff Wiernik »

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.

User avatar
rdonnay
Site Admin
Posts: 4733
Joined: Wed Jan 27, 2010 6:58 pm
Location: Boise, Idaho USA
Contact:

Re: Invoke a api / webservice.

#7 Post by rdonnay »

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.

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.

skiman
Posts: 1185
Joined: Thu Jan 28, 2010 1:22 am
Location: Sijsele, Belgium
Contact:

Re: Invoke a api / webservice.

#8 Post by skiman »

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.
Best regards,

Chris.
www.aboservice.be

User avatar
PedroAlex
Posts: 231
Joined: Tue Feb 09, 2010 3:06 am

Re: Invoke a api / webservice.

#9 Post by PedroAlex »

Many thanks for your topics.
I will investigate.

Respects
Pedro Alex.
Pedro Alexandre

User avatar
Tom
Posts: 1173
Joined: Thu Jan 28, 2010 12:59 am
Location: Berlin, Germany

Re: Invoke a api / webservice.

#10 Post by Tom »

Hi, Cliff.
Just curious, what are the 3 lines of code.
Okay, eight lines. ;)

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."

Post Reply