I originally posted this to the xenapi mailing list but i dont think many are on there... here''s my question. My first attempt at this, trying to get php to interface with /var/run/xend/xen-api.sock (or even 127.0.0.1:9363 for that matter). I can make a connection to both the unix socket and the inet socket and write/read data. The problem is i always get the same responce back, also the responce back is in html, shouldnt it be in xml format? At the moment this is my code $fp = fsockopen("unix:///var/run/xend/xen-api.sock", 0, $errno, $errstr, 30); if (!$fp) { echo "$errstr ($errno)\n"; } else { $request = xmlrpc_encode_request("session.login_with_password", array("root","none")); fwrite($fp, $request."\n"); while (!feof($fp)) { echo fgets($fp, 128); } fclose($fp); } When i run the code i always get this responce back... <head> <title>Error response</title> </head> <body> <h1>Error response</h1> <p>Error code 400. <p>Message: Bad request version (''encoding="iso-8859-1"?>''). <p>Error code explanation: 400 = Bad request syntax or unsupported method. </body> Anybody know why this is happening, also ifi telnet to localhost port 9363 and paste in my own request same thing happens, error looks alittle diferent though.. Trying 127.0.0.1... Connected to localhost.localdomain (127.0.0.1). Escape character is ''^]''. <?xml version="1.0" encoding="iso-8859-1"?><methodCall><methodName>session.login_with_password</methodName><params> <param> <value><string>root</string></value></param><param><value><string>none</string></value></param></params></methodCall> <head> <title>Error response</title> </head> <body> <h1>Error response</h1> <p>Error code 400. <p>Message: Bad request syntax (''<?xml version="1.0" encoding="iso-8859-1"?><methodCall><methodName>session.login_with_password</methodName><params> <param> <value><string>root</string></value></param><param><value><string>password</string></value></param></params></methodCall>''). <p>Error code explanation: 400 = Bad request syntax or unsupported method. </body> Connection closed by foreign host. ~Shaun _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
On Thu, Dec 06, 2007 at 12:19:26PM -0800, Shaun R. wrote:> I originally posted this to the xenapi mailing list but i dont think many > are on there... here''s my question. > > > My first attempt at this, trying to get php to interface with > /var/run/xend/xen-api.sock (or even 127.0.0.1:9363 for that matter). I can > make a connection to both the unix socket and the inet socket and write/read > data. The problem is i always get the same responce back, also the responce > back is in html, shouldnt it be in xml format? At the moment this is my > code > > $fp = fsockopen("unix:///var/run/xend/xen-api.sock", 0, $errno, $errstr, > 30); > if (!$fp) { > echo "$errstr ($errno)\n"; > } else { > $request = xmlrpc_encode_request("session.login_with_password", > array("root","none")); > fwrite($fp, $request."\n"); > while (!feof($fp)) { > echo fgets($fp, 128); > } > fclose($fp); > } > > When i run the code i always get this responce back... > > <head> > <title>Error response</title> > </head> > <body> > <h1>Error response</h1> > <p>Error code 400. > <p>Message: Bad request version (''encoding="iso-8859-1"?>''). > <p>Error code explanation: 400 = Bad request syntax or unsupported method. > </body> > > > Anybody know why this is happening, also ifi telnet to localhost port 9363 > and paste in my own request same thing happens, error looks alittle diferent > though..You''re sending the body content, but not the HTTP request headers. -- lfr 0/0 _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
Ahh, so what should the headers look like? POST / HTTP/1.0 User-Agent: MyScript Host: localhost Content-Type: text/xml Content-length: xxx ~Shaun _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users
On Thu, Dec 06, 2007 at 10:22:50PM -0800, Shaun R. wrote:> Ahh, so what should the headers look like?It''s standard XML-RPC stuff. Here''s a tcpdump capture: Client request: POST / HTTP/1.0 Host: localhost:9363 User-Agent: xmlrpclib.py/1.0.1 (by www.pythonware.com) Content-Type: text/xml Content-Length: 233 <?xml version=''1.0''?> <methodCall> <methodName>session.login_with_password</methodName> <params> <param> <value><string>me</string></value> </param> <param> <value><string>mypassword</string></value> </param> </params> </methodCall> Server response: HTTP/1.1 200 OK Server: BaseHTTP/0.3 Python/2.5 Date: Fri, 02 Nov 2007 17:54:44 GMT Content-Type: text/xml Content-Length: 313 <?xml version=''1.0''?> <methodResponse> <params> <param> <value><struct> <member> <name>Status</name> <value><string>Success</string></value> </member> <member> <name>Value</name> <value><string>1fb54ea1-b233-4bc4-7ec1-4bac5fe915da</string></value> </member> </struct></value> </param> </params> </methodResponse> -- lfr 0/0 _______________________________________________ Xen-users mailing list Xen-users@lists.xensource.com http://lists.xensource.com/xen-users