09-06-2017
01:00 PM
- last edited on
03-25-2019
01:21 PM
by
ciscomoderator
Hey All,
I am writing some PHP to do various tasks to my ACI environment from a web GUI I am building. I am able to submit GET requests to my APIC ok with no issue, but I am not receiving any response when I do any post...even a simple login. Below is my code. The POST request works fine from Postman. Anyone have any thoughts why I am not getting any response back from those of you who have done something similar?
<?php
$url = 'https://labapic1/api/aaaLogin.xml';
$data = '<aaaUser name="myloginID" pwd="myPassword" />';
$curl = curl_init();
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
//Ignore cert errors...
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
$response = curl_exec($curl);
//Check for errors...
if(!curl_exec($curl)){
die('Error: "' . curl_error($curl) . '" - Code: ' . curl_errno($curl));
}
curl_close($curl);
//Print output to screen
echo "<hr>";
echo "Date: ", date("Y-m-d") , "<br>";
echo "Time: ", date("h:i:sa") , "<br><br>";
echo "URL: ", $url, "<br><br>";
echo "Response: ", $response, "<br><br>";
?>
04-09-2020 08:53 AM
Hello!
Can you please show an exaple of a working get request to your lab apic with php curl?
Greetings, Mario
04-10-2020 01:50 AM
Hello!
Maybe you have to set header options for your post. I have seen a lot examples, where a header was set. And maybe you can try it with uncomment the ssl check. I will start making tests in my lab next week.
Greetings, Mario
04-10-2020 10:06 AM
I tested your scripts, seems to be working fine, when I look at the browser data we are receiving expected return from the APIC. for some reason it is not printing it properly though.
I am no PHP expert, my guess is may be some XML formatting issue with PHP that is is not able to print the return data.
Discover and save your favorite ideas. Come back to expert answers, step-by-step guides, recent topics, and more.
New here? Get started with these tips. How to use Community New member guide