1. Thierry Garrigues
  2. PowerBuilder
  3. Thursday, 22 September 2022 12:56 PM UTC

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;
?>
Thierry Garrigues Accepted Answer Pending Moderation
  1. Friday, 23 September 2022 06:24 AM UTC
  2. PowerBuilder
  3. # 1

Hi 

It works now. I put the corresponding code.

Thanks for your help.

Regards 

Thierry 

string ls_data
ls_data += '<?xml version="1.0" encoding="utf-8"?>'
ls_data += '<Product xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">'
ls_data += ' <OxID>5282552</OxID>'
ls_data += ' <ItemSKU>85852</ItemSKU>'
ls_data += '</Product>'

ls_data = inv_coderobject.of_url_encode(ls_data, EncodingUTF8!)

string ls_appId = "xxx"
ls_appId = inv_coderobject.of_url_encode(ls_appId, EncodingUTF8!)

string ls_token = "yyy"
ls_token = inv_coderobject.of_url_encode(ls_token, EncodingUTF8!)

string ls_methode = "ProductGet"
ls_methode = inv_coderobject.of_url_encode(ls_methode, EncodingUTF8!)

string ls_body
ls_body = 'Data=' + ls_data + "&AppId=" + ls_appId + "&Token="+ ls_token + "&Method=" + ls_methode

ll_ret = inv_httpclient.setrequestheader("charset", "UTF-8", true)
ll_ret = inv_httpclient.setrequestheader("content-type" , "application/x-www-form-urlencoded", true)
ll_ret = inv_httpclient.setrequestheader("Content-length" , string(len(ls_body)), true)

ll_ret =inv_httpclient.sendrequest('POST',"https://webservices.oxatis.com/webservices/httpservices/productservices.aspx", ls_body, EncodingUTF8!)
Comment
  1. Arnd Schmidt
  2. Friday, 23 September 2022 08:14 AM UTC
Great! Thanks for providing your small piece of the working code!
  1. Helpful
There are no comments made yet.
Thierry Garrigues Accepted Answer Pending Moderation
  1. Thursday, 22 September 2022 13:22 PM UTC
  2. PowerBuilder
  3. # 2

I want to use httpclient.sendrequest('POST', url,  body, EncodingUTF8!)

but I don't know what the PHP code does:

curl_setopt($objCurl, CURLOPT_POSTFIELDS, $strParams);

Thanks 

Comment
  1. Arnd Schmidt
  2. Thursday, 22 September 2022 21:22 PM UTC
The Statement sets the data to be posted.

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
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.
We use cookies which are necessary for the proper functioning of our websites. We also use cookies to analyze our traffic, improve your experience and provide social media features. If you continue to use this site, you consent to our use of cookies.