POST-ing XML in AngularJS

2019-01-27 02:47发布

问题:

I've been looking for hours for some angularjs documentation that explains how to POST xml data using the $http object. Does angular simply not offer it with their $http object? The code:

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

回答1:

I came here looking for the same thing, however I tried Skyler's solution and it did not work. I changed the content type to 'application/xml' and it worked. Here is the snippet:

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


回答2:

Figured it out. The Content-Type is threw me for a while. Seemed that application/xml made more sense. Oh well, whatever works!

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