Asp classic 使用xmlhttp(ASP)发布-错误响应:无输入XML数据
请看以下代码:Asp classic 使用xmlhttp(ASP)发布-错误响应:无输入XML数据,asp-classic,xmlhttprequest,Asp Classic,Xmlhttprequest,请看以下代码: <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<
<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>
这次我得到了错误响应:没有输入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);
}
?>
我只需要在后台/后端运行表单-所以我很乐意得到正确的代码
谢谢试试这样的方法:
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文档
另请参阅这篇关于同一主题的知识库文章:
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