Friday, November 19, 2021

Passing a URL to a PHP to Call GSX

 GSSX requires user site to be white listed before allowing access. Since our customer are using multiple applications that access GSX. The whitelisted server is not on the same server as our web program. User need to post data to the web server which in turn send a request to a central server which then send the request to GSX. 

Sending normal requests is simple but since GSX has many APIs that have a mix of "GET and POST"., The sending of data to GSX become complex as we have to send specific URL to get the right result. Now sending a POST/GET that contains URL as parameter is not that simple especially when the URL is mixed with other parameters. It need to be url-encoded properly.

PHP CURL uses query method to do both POST/GET thus the query works on both.

Luckily, there is a PHP function that could compose the post parameters. It is called HTTP_BUILD_QUERY. You just need to send an array of the parameters and it will compose the parameters properly. This including sending a URL as data.

The following is an example 

$data= array(

"id" => "1234567"

,"address" => "https://gsxserver.com/returns"

);

$params = http_build_query($data);

In your CURL request you simply use 

curl_setopt($ch, CURLOPT_POSTFIELDS, $param);

The central server PHP just need to get $_POST['xx'] to get the specific parameters.





No comments:

Post a Comment