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?
To configure and execute a CURL request, I suggest the following format:
I’m not sure aboutCURLOPT_POSTFIELDSbecause you don’t have specified what$requestStringcontains. It’s likely that this setting above is wrong. See curl POST format for CURLOPT_POSTFIELDS.Edit: You have specified it via
http_post_data:Curl supports that as well, just don’t pass as array, pass it as string: