protected function _replace($filePath, $photoId, $async = 0) { $params['async'] = $async; $params['photo_id'] = $photoId; $finalParams = $this->_httpUtility->assembleParams($this->_endpointReplace, $this->_configOAuth, $params); $request = new \Zend\Http\Request(); $request->setUri($this->_endpointReplace)->setMethod('POST')->setPost(new Parameters($finalParams)); $this->_httpClient->reset(); $this->_httpClient->setRequest($request); $this->_httpClient->setEncType(\Zend\Http\Client::ENC_FORMDATA, 'ITSCARO'); $this->_httpClient->setFileUpload($filePath, 'photo'); $response = $this->_httpClient->dispatch($request); $decodedResponse = simplexml_load_string($response->getBody()); if (!$decodedResponse instanceof \SimpleXMLElement) { throw new \Exception('Could not decode response: ' . $response->getBody(), self::ERR_RESPONSE_NOT_XML); } else { if ($decodedResponse['stat'] == 'ok') { if ($async) { return (string) $decodedResponse->ticketid; } else { return (string) $decodedResponse->photoid; } } else { throw new \Exception((string) $decodedResponse->err['msg'], (int) $decodedResponse->err['code']); } } }