如何在request.postAsync()中发布大型xml数据

时间:2019-05-24 13:27:34

标签: node.js xml request

我正在尝试将大型XML数据发布到另一台服务器,但是如果我使用Content-Length': Buffer.byteLength(xmldata)

,则会得到重复的字符串

我也使用了Content-Length': xmldata.length,所以得到了相同的结果。 如果我没有提到长度,那么它向我显示了另一台服务器上xml数据的一半。 如何使用request.postasync()方法将大型xml数据发送到其他服务器?

代码如下:

var xmldata="<?xml version="1.0"?>
<testsuites>
  <testsuite failures="2" tests="4" time="8">
    <testcase name="system should Run above 100" time="3">
      <failure message="expected speed above 100, but was 29.952576951218997 at marker post "/>
    </testcase>
    <testcase name="system should run below 100" time="0"/>
    <testcase name="system should run at 100" time="1"/>
    <testcase name="system should at least 100" time="0">
      <failure message="expected speed least 100, but was 29.952576951218997 at marker post "/>
    </testcase>
  </testsuite>
  <testsuite failures="0" tests="2" time="5">
    <testcase name="system should run above 50" time="2"/>
    <testcase name="system should run above 50" time="0"/>
  </testsuite>
  <testsuite failures="1" tests="2" time="10">
    <testcase name="system should rn above 30" time="3">
      <failure message="expected speed above 30, but was 29.952576951218997 at marker post "/>
    </testcase>
    <testcase name="leader should run below 30" time="0"/>
  </testsuite>
</testsuites>";

request.postAsync({ url: result.callBackUrl,
                    headers:{'Content-Type': 'text/xml',
'Content-Length': Buffer.byteLength(xmldata)},
                                    body: xmldata,

                                });


**Output on other server:**

<?xml version="1.0"?>
<testsuites>
  <testsuite failures="2" tests="4" time="8">
    <testcase name="leader should Run above 100" time="3">
      <failure message="expected speed above 100, but was 29.952576951218997 at marker post "/>
    </testcase>
    <testcase name="leader should run below 100" time="0"/>
    <testcase name="leader should run at 100" time="1"/>
    <testcase name="leader should at least 100" time="0">
      <failure message="expected speed least 100, but was 29.952576951218997 at marker post "/>
    </testcase>
  </testsuite>
  <testsuite failures="0" tests="2" time="5">
    <testcase name="leader should run above 50" time="2"/>
    <testcase name="leader should run above 50" time="0"/>
  </testsuite>
  <testsuite failures="1" tests="2" time="10">
    <testcase name="leader should rn above 30" time="3">
      <failure message="expected speed above 30, but was 29.952576951218997 at marker post "/>
    </testcase>
    <testcase name="leader should run below 30" time="0"/>
  </testsuite>
</testsuites>on="1.0"?>
<testsuites>
  <testsuite failures="2" tests="4" time="8">
    <testcase name="leader should Run above 100" time="3">
      <failure message="expected speed above 100, but was 29.952576951218997 at marker post "/>
    </testcase>
    <testcase name="leader should run below 100" time="0"/>
    <testcase name="leader should run at 100" time="1"/>
    <testcase name="leader should at least 100" time="0">
      <failure message="expected speed least 100, but was 29.952576951218997 at marker post "/>
    </testcase>
  </testsuite>
  <testsuite failures="0" tests="2" time="5">
    <testcase name="leader should run above 50" time="2"/>
    <testcase name="leader should run above 50" time="0"/>
  </testsuite>
  <testsuite failures="1" tests="2" time="10">
    <testcase name="leader should rn above 30" time="3">
      <failure message="expected speed above 30, but was 29.952576951218997 at marker post "/>
    </testcase>
    <testcase name="leader should run below 30" time="0"/>
  </testsuite>
</

0 个答案:

没有答案