Calling a webservice with hbcurl on linux (Dummy question)

357 views
Skip to first unread message

to...@skynet.be

unread,
Jun 1, 2012, 5:09:51 PM6/1/12
to Harbour Users
Hi,

I can't seem to get curl working.
I want to call a web service via CURL.

I have created the correct XML with soapUI and brought that into
the .prg file.

When i check with wireshark, I can see that the webservice is posted
but it does not seem to take the HTTP headers into account when
posting the message onto the webservice.

I get from the webservice back : "The server cannot service the
request because the media type is unsupported"

This is the example code I am trying to work :

#include "hbcurl.ch"

#include "common.ch"
#include "fileio.ch"


FUNCTION Main( )
LOCAL exitStatus
LOCAL endpointUrl

LOCAL postData
LOCAL curlHandle
LOCAL curlErr
LOCAL cHeader

/* Exit status to return */
exitStatus := 0
endpointUrl = "http://wsf.cdyne.com/WeatherWS/Weather.asmx"

// Parameters for call

postData := '<soapenv:Envelope xmlns:soapenv="http://
schemas.xmlsoap.org/soap/envelope/" xmlns:weat="http://ws.cdyne.com/
WeatherWS/">'
postData += '<soapenv:Header/>'
postData += '<soapenv:Body>'
postData += '<weat:GetWeatherInformation/>'
postData += '</soapenv:Body>'
postData += '</soapenv:Envelope>'

? postData

cHeader := "Accept-Encoding: gzip,deflate" + CHR(13) + CHR(10)
cHeader +="Content-Type: text/xml;charset=UTF-8" + CHR(13) + CHR(10)
cHeader +='SOAPAction: "http://ws.cdyne.com/WeatherWS/
GetWeatherInformation"' + CHR(13) + CHR(10)
cHeader +="User-Agent: Jakarta Commons-HttpClient/3.1" + CHR(13) +
CHR(10)

? cHeader

/* Initialise libcurl */
curl_global_init()

/* Get a curl handle */
curlHandle := curl_easy_init()

IF .NOT. EMPTY(curlHandle)

curl_easy_setopt(curlHandle,HB_CURLOPT_HTTPHEADER, cHeader)
/* Set the endpoint to send the POST to */
curl_easy_setopt(curlHandle, HB_CURLOPT_URL, endpointUrl);
/* Specify the POST data */
curl_easy_setopt(curlHandle, HB_CURLOPT_POSTFIELDS, postData);
/* Execute the POST, response goes to STDOUT */


curlErr = curl_easy_perform(curlHandle);
/* Report any errors */

IF .NOT. EMPTY(curlErr)
? curl_easy_strerror(curlErr)
ENDIF
ELSE
? "No handle"
ENDIF

IF .NOT. EMPTY(curlHandle)
/* Clean-up libcurl */
curl_global_cleanup()
ELSE
exitStatus = 1
ENDIF

/* Return the exit status */

RETURN exitStatus

to...@skynet.be

unread,
Jun 1, 2012, 5:59:25 PM6/1/12
to Harbour Users
I have found in the mean time that I need to pass an Array for the
HTTP Headers
When I code it as below. I get a response from the webservice to
standard out.
Next step is getting the response into a variable.


#include "hbcurl.ch"

#include "common.ch"
#include "fileio.ch"


FUNCTION Main( )
LOCAL exitStatus
LOCAL endpointUrl

LOCAL postData
LOCAL curlHandle
LOCAL curlErr
LOCAL aHeader

/* Exit status to return */
exitStatus := 0
endpointUrl = "http://wsf.cdyne.com/WeatherWS/Weather.asmx"

// Parameters for call

postData := '<soapenv:Envelope xmlns:soapenv="http://
schemas.xmlsoap.org/soap/envelope/" xmlns:weat="http://ws.cdyne.com/
WeatherWS/">'
postData += '<soapenv:Header/>'
postData += '<soapenv:Body>'
postData += '<weat:GetWeatherInformation/>'
postData += '</soapenv:Body>'
postData += '</soapenv:Envelope>'

? postData

aHeader := {}
AADD(aHeader,"Accept-Encoding: gzip,deflate" )
AADD(aHeader,"Content-Type: text/xml;charset=UTF-8" )
AADD(aHeader,'SOAPAction: "http://ws.cdyne.com/WeatherWS/
GetWeatherInformation"' )
AADD(aHeader,"User-Agent: Jakarta Commons-HttpClient/3.1" )

/* Initialise libcurl */
curl_global_init()

/* Get a curl handle */
curlHandle := curl_easy_init()

IF .NOT. EMPTY(curlHandle)

/* Specify the Header data */
curl_easy_setopt(curlHandle,HB_CURLOPT_HTTPHEADER, aHeader)

Com1 Software

unread,
Jun 4, 2012, 12:42:36 PM6/4/12
to Harbour Users
Hello,

I am trying to work with curl in linux as well.

Are you linking any libraries for the curl, if so what what libs?

Any help would be most appreciated.

Thanks
Dave

Claudia Neumann

unread,
Jun 4, 2012, 1:36:24 PM6/4/12
to harbou...@googlegroups.com, Com1 Software
Hi Dave,

-lhbcurl
-lcurl

CU

Claudia

vszakats

unread,
Jun 4, 2012, 2:05:57 PM6/4/12
to harbou...@googlegroups.com, Com1 Software
hbcurl.hbc

-- Viktor

Com1 Software

unread,
Jun 6, 2012, 1:41:35 PM6/6/12
to Harbour Users
Hello all,
I appreciate the help.
I was able to build the lib I need using the following

cd harbour/contrib/hbcurl

../../bin/linux/gcc/hbmk2 ../make.hbs

now this compiles fine
hbmk2 -lhbcurl -lcurl test.prg

Thanks
Dave

Tarun Vaghasia

unread,
Sep 19, 2018, 7:12:03 AM9/19/18
to Harbour Users
Worked!
Reply all
Reply to author
Forward
0 new messages