以下是我正在使用的代码。我理解95%的。
httpRequest
功能)。 requestTemplate
),它对返回XML响应的URL进行POST。 prefillTemplate
)的目的是从XML响应中收集某个变量(for exp $xml->title;
)并将其发布到另一个URL。 我遇到的问题是,如何从XML响应中收集该变量并将其抛给prefillTemplate
函数?
function httpRequest($url, $headers, $method, $body = NULL) {
if (!$method) {
$method = "GET";
};
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
// Append 'api-token' to Headers
curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers, "api-token: $this- >secure_token")); // Set the headers.
if ($body) {
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $body);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
// Append 'api-token' to Headers
curl_setopt($curl, CURLOPT_HTTPHEADER, array($headers, "Content-Type: text/xml;charset=utf-8", "api-token: $this->secure_token"));
}
$data = curl_exec($curl);
if ($this->debug) {
echo "In httpRequest: Recieved DATA\n===========\n" . $data . "\n===========\n";
}
curl_close($curl);
return $data;
}
public function requestTemplate(){
$url = $this->secure_base_url . "blahblah/prepackage.xml";
//echo "Getting documents...\n";
$header = Array();
$response = $this->httpRequest($url, $header, "POST");
return $response;
}
function prefillTemplate($data){
$url = $this->secure_base_url . "blahblah/templates.xml";
$xml = "<?xml version='1.0' encoding='UTF-8'?><template><guid>".$data."</guid></template>";
echo $xml;
$header = Array();
$response = $this->httpRequest($url, $header, "POST", $xml);
return $response;
}