9 class WP_HTTP_IXR_Client extends IXR_Client {
11 function __construct($server, $path = false, $port = false, $timeout = 15) {
13 // Assume we have been given a URL instead
14 $bits = parse_url($server);
15 $this->scheme = $bits['scheme'];
16 $this->server = $bits['host'];
17 $this->port = isset($bits['port']) ? $bits['port'] : $port;
18 $this->path = !empty($bits['path']) ? $bits['path'] : '/';
20 // Make absolutely sure we have a path
24 $this->scheme = 'http';
25 $this->server = $server;
29 $this->useragent = 'The Incutio XML-RPC PHP Library';
30 $this->timeout = $timeout;
34 $args = func_get_args();
35 $method = array_shift($args);
36 $request = new IXR_Request($method, $args);
37 $xml = $request->getXml();
39 $port = $this->port ? ":$this->port" : '';
40 $url = $this->scheme . '://' . $this->server . $port . $this->path;
42 'headers' => array('Content-Type' => 'text/xml'),
43 'user-agent' => $this->useragent,
47 // Merge Custom headers ala #8145
48 foreach ( $this->headers as $header => $value )
49 $args['headers'][$header] = $value;
51 if ( $this->timeout !== false )
52 $args['timeout'] = $this->timeout;
54 // Now send the request
56 echo '<pre class="ixr_request">' . htmlspecialchars($xml) . "\n</pre>\n\n";
58 $response = wp_remote_post($url, $args);
60 if ( is_wp_error($response) ) {
61 $errno = $response->get_error_code();
62 $errorstr = $response->get_error_message();
63 $this->error = new IXR_Error(-32300, "transport error: $errno $errorstr");
67 if ( 200 != wp_remote_retrieve_response_code( $response ) ) {
68 $this->error = new IXR_Error(-32301, 'transport error - HTTP status code was not 200 (' . wp_remote_retrieve_response_code( $response ) . ')');
73 echo '<pre class="ixr_response">' . htmlspecialchars( wp_remote_retrieve_body( $response ) ) . "\n</pre>\n\n";
75 // Now parse what we've got back
76 $this->message = new IXR_Message( wp_remote_retrieve_body( $response ) );
77 if ( ! $this->message->parse() ) {
79 $this->error = new IXR_Error(-32700, 'parse error. not well formed');
83 // Is the message a fault?
84 if ( $this->message->messageType == 'fault' ) {
85 $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);