Skip to content

Instantly share code, notes, and snippets.

@steveosoule
Last active July 6, 2022 16:33
Show Gist options
  • Save steveosoule/51fbe51c085d85efccf8079a7fd1d836 to your computer and use it in GitHub Desktop.
Save steveosoule/51fbe51c085d85efccf8079a7fd1d836 to your computer and use it in GitHub Desktop.
Miva - mvt:call to PHP-middleware to perform HTTP GET with POST Data
<mvt:assign name="l.data_for_api:thing_1" value="'Foobar'" />
<mvt:assign name="l.data_for_api:thing_2" value="'Lorem ipsum...'" />
<mvt:capture variable="l.json_string">
<mvt:do file="g.Module_JSON" name="l.success" value="JSON_Output( l.data_for_api )" />
</mvt:capture>
<mvt:call action="'https://ssoule.mivamerchantdev.com/php/mvt-call-converter.php'" method="'GET'" fields="'json_string'">
<mvt:eval expr="s.callvalue" />
</mvt:call>
<?php
$url = 'https://ssoule.mivamerchantdev.com/php/example-api.php';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_POSTFIELDS, $_REQUEST['json_string']);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
curl_close($ch);
echo $result;
<?php
$fp = fopen('php://input', 'r');
$data_for_api = stream_get_contents($fp);
echo "Request Method: " . $_SERVER['REQUEST_METHOD'] . "\n\n";
echo "l.data_for_api: \n\n $data_for_api";
Request Method: GET
l.data_for_api:
{
"thing_1": "Foobar",
"thing_2": "Lorem ipsum..."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment