I have a hosted server with curl installed, but not http_post_data() pecl.
I'm trying to translate this (working) http_post_data() code to curl:
$responseString = @http_post_data("http://" . $this->username . ":" . $this->password ."@" . $this->webserviceHost . $this->requestUriBase .$request,
$requestString,
array('http_auth' => $this->username . ":" . $this->password, 'headers' => array('Content-Type' => 'text/xml')));
I've tried:
$url = "http://" . $this->username . ":" . $this->password ."@" . $this->webserviceHost . $this->requestUriBase .$request;
curl_setopt($this->curl, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml'));
curl_setopt($this->curl, CURLOPT_URL, $url);
curl_setopt($this->curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
curl_setopt(CURLOPT_USERPWD, "[$this->username]:[$this->password]");
curl_setopt ($this->curl, CURLOPT_POST, true);
curl_setopt ($this->curl, CURLOPT_POSTFIELDS, array($requestString));
$content = curl_exec($this->curl);
... and failed: couldn't connect to host
What's the correct code?