Send XML via HTTP post
Hejsa,Jeg har brug for at sende et XML dokument til en server, hvor jeg indkluderer nogle varible i headeren. Men jeg kan simpelthen ikke få det til at virke.
Her er min kode:
----------------
$body = '<?xml version="1.0"?>
<RTMWeblet>
<!– xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" –>
<!– xsi:noNamespaceSchemaLocation="http://172.18.252.143/rtm/RTMWebletReq.xsd"> –>
<RTMEmailToEmailAddress>
<AcknowledgementsTo>
<EmailAddress>xxx</EmailAddress>
<Option>0</Option>
</AcknowledgementsTo>
<ClientName>xxx</ClientName>
<SiteName>xxx</SiteName>
<CampaignName>xxx</CampaignName>
<MailingName>xxx</MailingName>
<MaximumDeferrableMinutes>20</MaximumDeferrableMinutes>
<ActionAfterDeferredTime>0</ActionAfterDeferredTime>
<ToEmailAddress>
<EventEmailAddress>
<EmailAddress>xxx</EmailAddress>
<EventVariables>
<Variable>
<Name>EventVar:ev1</Name>
<Value>
<![CDATA[
<SetVar Name="var:aktiv” Value="1">
<SetVar Name="var:navn” Value="xxx">
]]>
</Value>
</Variable>
</EventVariables>
</EventEmailAddress>
</ToEmailAddress>
</RTMEmailToEmailAddress>
</RTMWeblet>';
$url = "http://rtm.ddc.dartmail.net/weblet/weblet.dll";
$res = (PostIt($body,$url));
echo implode('',$res);
function PostIt($DataStream, $URL) {
// Strip http:// from the URL if present
$URL = ereg_replace("^http://", "", $URL);
// Separate into Host and URI
$Host = substr($URL, 0, strpos($URL, "/"));
$URI = strstr($URL, "/");
// Form up the request body
$ReqBody = "";
while (list($key, $val) = each($DataStream)) {
if ($ReqBody) $ReqBody.= "&";
$ReqBody.= $key."=".urlencode($val);
}
$ContentLength = strlen($body);
// Generate the request header
$ReqHeader =
"Username: talefod_dmc\n".
"Password: Talefod3Connect\n".
"Servername: EDC2\n".
$body."\n";
// Open the connection to the host
$socket = fsockopen($Host, 80, &$errno, &$errstr);
if (!$socket) {
$Result["errno"] = $errno;
$Result["errstr"] = $errstr;
return $Result;
}
$idx = 0;
fputs($socket, $ReqHeader);
while (!feof($socket)) {
$Result[$idx++] = fgets($socket, 128);
}
return $Result;
}
--------------
Når jeg sender dette afsted får jeg følgende svar fra serveren:
HTTP/1.1 400 Bad Request Server: Microsoft-IIS/5.0 Date: Thu, 08 Jun 2006 14:21:11 GMT Content-Type: text/html Content-Length: 87 The parameter is incorrect.
Hvor jeg skulle få:
<?xml version="1.0" encoding="US-ASCII" ?>
- <DMResponse xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://rtm.ddc.dartmail.net/weblet/RTMResponse.xsd">
<Code>-100</Code>
<Description>The Servername provided in the HTTP header is unknown.</Description>
</DMResponse>
Her er et link til et pl-script som virker (bare fyld noget tilfældigt i):
http://demo.doubleclick.com/rtm/rtm_demo.pl
Håber nogen kan hjlæpe :)
/Sune