请查看以下代码:
<form id='myform' name='myform' action='http://www.xxx.xom' method='post' accept-charset='UTF-8'>
<input type='input' name='xmlData' value='<?xml version="1.0"?>
<order_zip>23222</order_zip>
<shipping_id>15</shipping_id>
<products><product> <product_id>230</product_id> <quantity>40</quantity></product></products>'>
</form>
当我发送表单数据时 - 我的响应为:确定。
但是我需要在后端(背景)中进行。
所以我的代码是:
set xmlhttp = server.createobject("MSXML2.XMLHTTP")
xmlhttp.Open "POST",URL,False
xmlhttp.SetRequestHeader "Content-Type","text/xml;charset=UTF-8"
xmlhttp.Send xmlstring
Response.write(xmlhttp.response.text)
这次我收到错误回复:没有输入XML数据 技术人员只知道php没有asp - 所以他不知道我的代码需要改变什么。
这是php代码示例:
<?php
$xml['xmlData'] .= '<order_zip>187654</order_zip>';
$xml['xmlData'] .= '<shipping_id>3</shipping_id>';
$xml['xmlData'] .= '<products>';
$xml['xmlData'] .= '<product><product_id>458</product_id><quantity>11</quantity></product>';
$connection = curl_init();
curl_setopt($connection, CURLOPT_URL, "http://api.xml.com/xml/sendOrder");
curl_setopt($connection, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($connection, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($connection, CURLOPT_POST, 1);
curl_setopt($connection, CURLOPT_POSTFIELDS, $xml);
curl_setopt($connection, CURLOPT_RETURNTRANSFER, 1);
set_time_limit(108000);
$strResponse = curl_exec($connection);
if(curl_errno($connection)) {
print 'Curl error: ' . curl_error($connection);
}
curl_close($connection);
print_r($strResponse);
}
?>
我只需要在后台/后端运行表单 - 所以我很乐意获得正确的代码。
谢谢
答案 0 :(得分:0)
尝试这样的事情:
xmlstring = "<root>" & _
" <order_zip>23222</order_zip>" & _
" <shipping_id>15</shipping_id>" & _
" <products>" & _
" <product>" & _
" <product_id>230</product_id>" & _
" <quantity>40</quantity>" & _
" </product>" & _
" </products>" & _
"</root>"
set xmlhttp = Server.CreateObject("MSXML2.ServerXMLHTTP")
xmlhttp.Open "POST", URL, False
xmlhttp.SetRequestHeader "Content-Type","application/x-www-form-urlencoded"
xmlhttp.Send xmlstring
Response.write xmlhttp.responseText
我在XML中添加了一个根元素,否则它将不是一个有效的XML文档。
另请参阅此KB文章,内容涉及同一主题:http://support.microsoft.com/kb/290591