Hi
Could you help me to translate this PHP code to PowerBuilder.
It is used to call a REST-type web service.
Thanks for your help.
Thierry
DEFINE('CFG_APP_ID', '???????????');
DEFINE('CFG_TOKEN', '?????????????????');
function CallWebService($strCallURL, $strMethod, $strBody, &$bResult){
$strURL = $strCallURL;
$strParams = 'Data=' . urlencode($strBody);
$strParams .= '&AppId=' . urlencode(CFG_APP_ID);
$strParams .= '&Token=' . urlencode(CFG_TOKEN);
$strParams .= '&Method=' . urlencode($strMethod);
$objCurl = curl_init();
curl_setopt($objCurl, CURLOPT_URL, $strURL);
curl_setopt($objCurl, CURLOPT_POST, 1);
curl_setopt($objCurl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($objCurl, CURLOPT_POSTFIELDS, $strParams);
curl_setopt($objCurl, CURLOPT_HTTPHEADER,
array("Content-Type: application/x-www-form-urlencoded", "Content-length: " . strlen($strParams)));
$strResponse = curl_exec($objCurl);
if ( !curl_errno($objCurl) ) {
$bResult = true;
} else {
$bResult = false;
$strResponse = 'An error occured: ' . curl_error($objCurl);
}
return $strResponse;
}
//call function
$strResponse =
CallWebService('https://webservices.oxatis.com/WebServices/httpservices/productservices.aspx' ,
'ProductGet',
'<?xml version="1.0" encoding="utf-8"?> <Product xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"><OxID>9999999</OxID></Product>', $bResult);
if ( $bResult ) {
header("Content-type: text/xml");
}
echo $strResponse;
?>
Please have a look at these resources ...
https://community.appeon.com/index.php/articles-blogs/tutorials-articles/2-powerbuilder/236-call-soap-web-services-using-httpclient-object
https://community.appeon.com/index.php/blogs/recent-blogs/powerbuilder-s-soap-to-restfulevolution
https://community.appeon.com/index.php/articles-blogs/tutorials-articles/2-powerbuilder/296-how-to-use-httpclient-or-restclient-to-call-an-api-with-basic-authentication
https://community.appeon.com/index.php/articles-blogs/tutorials-articles/2-powerbuilder/181-powerbuilder-2017-r2-new-feature-rest
HTH
Regards... Chris
Key=Value pairs are simply concatenated with '&' as separator.
But be sure not to misuse the "=" and "&" signs inside your data - to mask that stuff the urlencode() Method is your friend in php.
PowerBuilder offers: coder.UrlEncode ( variable ) .
https://community.appeon.com/index.php/webinars/elevate-discussion/posting-forms-with-httpclient?limitstart=0#reply-27067
hth
Arnd