首页 > 解决方案 > 节点 - 通过请求将 xml 发布到服务器

问题描述

我尝试通过 xmls 与 REST api 通信。我生成一个 xml 并使用Restlet Client(用于测试 REST API 的 chrome 扩展程序)对其进行测试。它工作正常,我收到响应 XML。如果我尝试使用request-promise发送,我会收到

 '<html><head><title>Error</title></head><body>Internal Server Error</body></html>'

在 err.response.body 中。

API 服务器的响应始终是 XML,所以我不明白为什么它是“html”。

这是代码

  options = {
    uri: uri,
    header: {
      'Content-Type': 'application/xml ',
      'Accept'      : 'application/xml '
    },
    body: xml // I use the same xml in Restlet Client's body
  }
  rp.post(options).then(response=>{
    console.log('------SUCCESS-----')
    console.log(response)
  }).catch(err=>{
    console.log('------ERROR-----')
    console.log(err.response)
  })

如果您需要任何附加信息,请告诉我。

标签: node.jsrequest

解决方案


推荐阅读