Reputation: 31
I have a Datasnap Server and a have a method named :
function TServerMethodsMain.AddCity( ACity : TJSONObject ) : Boolean ;
I did small php code below to invoke this method.
<?php
class city
{
public $id;
public $description;
public $uf;
}
$objcity = new city ;
$objcity -> id = 1 ;
$objcity -> description = 'MY CITY' ;
$objcity -> uf = 'XX' ;
$url = 'http://192.168.1.101:8088/datasnap/rest/TServerMethodsMain/AddCity/' ;
$url .= json_encode( $objcity ) ;
$page = file($url) ;
$show = json_decode($page[0]);
echo '<pre>';
print_r ($show);
echo '</pre>';
?>
I got this error message from browser (Firefox or IE) :
Warning: file(http://192.168.1.101:8088/datasnap/rest/TServerMethodsMain/AddCity/{"id":1,"description":"MY CITY","uf":"XX"}) [function.file]: failed to open stream: HTTP request failed! HTTP/1.1 500 Internal Server Error in C:\xampp\htdocs\json-php\index.php on line 19
Well, I have others methods that works fine with this php code, but only if I pass as parametrer Primitive Types : String, Integer...
I did a debug and see that problem happens at moment I need to convert parameter JSONObject into Object ( unMarshalll ). When I invoke this method by Client Delphi Win32 it works fine !
Does anybody knows anything about the problem ?
Thanks !
Upvotes: 1
Views: 5337
Reputation: 999
This PHP Code works with DataSnap - Delphi XE2
$ch = curl_init();
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Accept: application/json", "Content-Type: text/xml; charset=utf-8"));
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, 'user:pass');
curl_setopt($ch, CURLOPT_URL, $param_url);
$response = curl_exec($ch);
$info = curl_getinfo($ch);
curl_close($ch);
Upvotes: 1
Reputation: 31
follow below a link with my answer
http://docwiki.embarcadero.com/RADStudio/en/Talk:DataSnap_REST_Messaging_Protocol
Upvotes: 0
Reputation: 1774
Your PHP code issue a GET request to the datasnap server. For complex parameters like JSONObject you need to use POST or PUT HTTP verb with proper JSONObject as message body. http://docwiki.embarcadero.com/RADStudio/en/DataSnap_REST_Messaging_Protocol#Parameters_in_the_URL
So, you need to send a POST request to the datasnap server. Check the documentations for further details. http://docwiki.embarcadero.com/RADStudio/en/DataSnap_REST_Messaging_Protocol
Upvotes: 1