I am trying to test an api call locally. It works fine on the live site but I want to be able to test some aspects of using the data return locally first.
Using MAMP and it is a Laravel app.
The variables are all set correctly on my local setup but for some reason the string that gets returned is empty.
It is showing that the credentials being sent are correct, but the return response, again, is empty when, on the live site, it has data.
Here is the code in the controller (env variables for the credentials are only thing before this in function)
$API_XML = urlencode("<GetAuthTokenRequest>\n</GetAuthTokenRequest>\n");
// NVPRequest for submitting to server
$nvpreq = "email=$API_UserName&password=$API_Password&xml=$API_XML";
echo "Request was $nvpreq\n\n";
$httpResponse = $this->Send_CE_XML_Request($nvpreq);
echo "Response was $httpResponse\n\n";
$my_reader = new XMLReader();
$my_reader->xml($httpResponse); <- FAILING HERE ACCORDING TO ERROR
$xml_result = "";
$xml_token = "";
$xml_errorcode = "";
$xml_errormsg = "";
while ($my_reader->read())
{
switch ($my_reader->nodeType)
{
case XMLReader::ELEMENT:
if ($my_reader->name == "Result")
{
$my_reader->read();
$xml_result = $my_reader->value;
}
else if ($my_reader->name == "Token")
{
$my_reader->read();
$xml_token = $my_reader->value;
}
else if ($my_reader->name == "ErrorCode")
{
$my_reader->read();
$xml_errorcode = $my_reader->value;
}
else if ($my_reader->name == "ErrorText")
{
$my_reader->read();
$xml_errormsg = $my_reader->value;
}
break;
}
}
if ($xml_result == "Error")
{
print "Error - error code was $xml_errorcode, error message was $xml_errormsg\n";
}
...
and then the send request code
private function Send_CE_XML_Request($request) {
$test_url = "http://ift.tt/28SXY0V";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $test_url);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// turning off the server and peer verification(TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_SSLVERSION, 6);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $request);
return curl_exec($ch);
}
This has had me stumped for a while and I have been putting off working it out, any help would be greatly appreciated as I am not even really quite sure where to start.
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/28YIrKE
via IFTTT
Aucun commentaire:
Enregistrer un commentaire