PHP: call to a REST api -
i trying call vchargeback api getting information on vcenter server. having issues this.
i have pass request xml data in request body. , have pass version url parameter. code have written
$xmlfile=simplexml_load_file('login.xml'); $ch = curl_init(); curl_setopt($ch, curlopt_post, 1); curl_setopt($ch, curlopt_postfields,$xmlfile);//passing xml file post field curl_setopt($ch, curlopt_timeout, 10); curl_setopt($ch, curlopt_url,"https://xx.xx.xx.xx/vcenter-cb/api/login");//setting url curl_setopt($ch, curlopt_returntransfer, true); curl_setopt($ch , curlopt_ssl_verifypeer , false );//since requesting https curl_setopt($ch , curlopt_ssl_verifyhost , false );//since requesting https curl_setopt($ch, curlopt_httpheader, array ('accept: ' . $this->accepttype )); $response=curl_exec($ch);//getting response $responseinfo=curl_getinfo($ch);//getting response headers
when execute, have 400 bad request response. noticed not sending version url parameter. should name : version value : 1.5.0 not knowing how send version url parameter. should send postfield how should send xml file request body.
please me...
regards, srinath
the chargeback interface not restful. it's xml portal resources @ given endpoints defined documentation. log in, fill in api_namespace
xml namespace provided installation, api_version
api version number, type
(which can "local" or "ldap"). name
, password
should obvious.
<request xmlns="$api_namespace/$api_version"> <users> <user> <type>$type</type> <name>$name</name> <password>$password</password> </user> </users> </request>
generate post request https://hostname/vcenter-cb/api/login?version=$api_version
raw post-data set xml above. remember keep session cookie sent after request returns, represents session server.
also, if you're using ldap logins, may have include ldapusers
child element below users
(as sibling of user
element) provide ldap credentials. documented in api programming guide vmware.
Comments
Post a Comment