how to use [GH] cUrl to load data from web api using GET method

Janosik 25 Feb, 2014
Hello,

I am trying to create a form, which will load data from web API using GET method.

I have this get method:

http://new.webaplikace.net/Booking.svc/GetFreeRoomTypeList?DateFrom=2011-01-01&DateTo=2011-12-31&UserId=1&TaskId=1001&TaskPassword=Test

it will return an xml which I want to show to the user after some formating. The parameters in the URL will change according to form fields in previous step. I want to use it in multipage setup.

I had this idea: In the first page, some data would be filled in, than after submit it will go to next form..In this next form I would make a curl request with params from previous form and then would show the response to the user.

First I need to make it work with single page only. I have created a form, set its method to GET and in onLoad event put the [GH] curl action before show HTML and debugger action. After some trial and error I have come up with this setting of curl action

TARGET:
http://new.webaplikace.net/Booking.svc/GetFreeRoomTypeList



PARAMS:
TaskPassword=Test
##CURLOPTS##
CURLOPT_HEADER=0
CURLOPT_RETURNTRANSFER=1
CURLOPT_TIMEOUT-200
CURLOPT_HTTPGET=1
CURLOPT_URL=http://new.webaplikace.net/Booking.svc/GetFreeRoomTypeList?DateFrom=2011-01-01&DateTo=2011-12-31&UserId=1&TaskId=1001&TaskPassword=Test


in the debug tab i see that it worked but I dont see the response with data...only that it was successful.

cURL info: Array ( [url] => http://new.webaplikace.net/Booking.svc/GetFreeRoomTypeList?DateFrom=2011-01-01&DateTo=2011-12-31&UserId=1&TaskId=1001&TaskPassword=Test [content_type] => application/xml; charset=utf-8 [http_code] => 200 [header_size] => 300 [request_size] => 166 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 0 [total_time] => 1.981 [namelookup_time] => 0.047 [connect_time] => 0.062 [pretransfer_time] => 0.062 [size_upload] => 0 [size_download] => 257 [speed_download] => 129 [speed_upload] => 0 [download_content_length] => 257 [upload_content_length] => 0 [starttransfer_time] => 1.981 [redirect_time] => 0 [certinfo] => Array ( ) [primary_ip] => 82.100.40.70 [primary_port] => 80 [local_ip] => 192.168.0.104 [local_port] => 38329 [redirect_url] => )
Response: 0Ok



Could someone please give me some clue what should I try? When I tried to use the classical way with the target url without params and line delimited params in the params view, then the request failed. So I had to create the url thru CURLOPT options

Maybe I should use something other than curl? I was also thinking about the data being loaded on the client thru AJAX call.


Thank you very much for your time
GreyHead 25 Feb, 2014
Hi Janosik,

The cURL response should be available after the action in $form->data['curl_gh']

Bob
Janosik 27 Feb, 2014
Thank you very much..I have eventualy figured it out with the custom code action, where I use the Curl functions. I am wandering what is the purpose of cUrl action, if you can do it directly in custom code? It is because convenience, that you could use curly replacer instead of $form->data?
I am now dealing with another problem. I have a multipage form which should start in module and continue in component. Is it possible to do it only with multipage form or should I use some redirect action or something else?

Thanks again.
GreyHead 27 Feb, 2014
Hi Janosik,

The purpose of the action is to make it a bit simpler to add cURL actions for users who aren't familiar with PHP. You can do anything with Custom Code, if you have the skills.

For your module problem I'd probably use two linked forms, one to start in the module and a second one to continue from there on.

Bob
This topic is locked and no more replies can be posted.