1

请看以下代码:

<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);
  }
  ?>

我只需要表单在后台/后端运行 - 所以我很乐意获得正确的代码。

谢谢

4

1 回答 1

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 文档。

另请参阅有关同一主题的知识库文章:http: //support.microsoft.com/kb/290591

于 2012-10-12T23:00:40.207 回答