【问题标题】:POST-ing XML in AngularJS在 AngularJS 中发布 XML
【发布时间】:2016-08-31 16:13:56
【问题描述】:

我一直在寻找一些 angularjs 文档,这些文档解释了如何使用 $http 对象发布 xml 数据。 Angular 是否根本不提供 $http 对象?代码:

$http({ 
  method: 'POST',
  url: 'http://10.0.0.123/PHP/itemsGet.php',
  data: '<searchKey id="whatever"/>',
  headers: { "Content-Type": 'application/x-www-form-urlencoded' }
})

【问题讨论】:

    标签: xml angularjs http post


    【解决方案1】:

    我来这里是为了寻找同样的东西,但是我尝试了 Skyler 的解决方案,但没有奏效。 我将内容类型更改为“应用程序/xml”并且它有效。 这是sn-p:

    $http({ 
        method: 'POST',
        url: 'http://10.0.0.123/PHP/itemsGet.php',
        data: '<searchKey id="whatever"/>',
        headers: { "Content-Type": 'application/xml' }
    })
    

    【讨论】:

    • "我尝试了 Skyler 的解决方案,但没有成功。我将内容类型更改为 'application/xml',并且成功了" 将内容类型更改为 application/xml 是 Skyler 的解决方案。
    • 好的,现在我看起来像个疯子,因为我在 Skyler 将答案更改为 xml 之前发布了我的答案
    • 他没有改成xml。不幸的是,发布的代码是“之前”代码,但解决方案一直是“似乎 application/xml 更有意义”
    【解决方案2】:

    想通了。 Content-Type 扔了我一会儿。似乎application/xml 更有意义。哦,好吧,任何工作!

    $http({ 
        method: 'POST',
        url: 'http://10.0.0.123/PHP/itemsGet.php',
        data: '<searchKey id="whatever"/>',
        headers: { "Content-Type": 'application/xml' }
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2021-08-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-07-07
      • 1970-01-01
      相关资源
      最近更新 更多