9 class WP_HTTP_IXR_Client extends IXR_Client {
10 function WP_HTTP_IXR_Client($server, $path = false, $port = 80, $timeout = 15) {
12 // Assume we have been given a URL instead
13 $bits = parse_url($server);
14 $this->scheme = $bits['scheme'];
15 $this->server = $bits['host'];
16 $this->port = isset($bits['port']) ? $bits['port'] : 80;
17 $this->path = !empty($bits['path']) ? $bits['path'] : '/';
19 // Make absolutely sure we have a path
23 $this->scheme = 'http';
24 $this->server = $server;
28 $this->useragent = 'The Incutio XML-RPC PHP Library';
29 $this->timeout = $timeout;
33 $args = func_get_args();
34 $method = array_shift($args);
35 $request = new IXR_Request($method, $args);
36 $xml = $request->getXml();
38 $url = $this->scheme . '://' . $this->server . ':' . $this->port . $this->path;
40 'headers' => array('Content-Type' => 'text/xml'),
41 'user-agent' => $this->useragent,
45 // Merge Custom headers ala #8145
46 foreach ( $this->headers as $header => $value )
47 $args['headers'][$header] = $value;
49 if ( $this->timeout !== false )
50 $args['timeout'] = $this->timeout;
52 // Now send the request
54 echo '<pre class="ixr_request">' . htmlspecialchars($xml) . "\n</pre>\n\n";
56 $response = wp_remote_post($url, $args);
58 if ( is_wp_error($response) ) {
59 $errno = $response->get_error_code();
60 $errorstr = $response->get_error_message();
61 $this->error = new IXR_Error(-32300, "transport error: $errno $errorstr");
65 if ( $response['response']['code'] != 200 ) {
66 $this->error = new IXR_Error(-32301, "transport error - HTTP status code was not 200 ({$response['response']['code']})");
71 echo '<pre class="ixr_response">' . htmlspecialchars($response['body']) . "\n</pre>\n\n";
73 // Now parse what we've got back
74 $this->message = new IXR_Message( $response['body'] );
75 if ( ! $this->message->parse() ) {
77 $this->error = new IXR_Error(-32700, 'parse error. not well formed');
81 // Is the message a fault?
82 if ( $this->message->messageType == 'fault' ) {
83 $this->error = new IXR_Error($this->message->faultCode, $this->message->faultString);