2

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' }
})
a better oliver
  • 26,330
  • 2
  • 58
  • 66
Skyler
  • 777
  • 1
  • 9
  • 34

2 Answers2

2

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' }
})
santiago arizti
  • 4,175
  • 3
  • 37
  • 50
  • _"I tried Skyler's solution and it did not work. I changed the content type to 'application/xml' and it worked"_ Changing the content type to application/xml **IS** Skyler's solution. – a better oliver Aug 31 '16 at 08:16
  • ok, now I look like a crazy person because I posted my answer before Skyler changed the answer to xml – santiago arizti Sep 01 '16 at 00:25
  • 1
    He didn't change it to xml. Unfortunately the posted code was the "before" code, but the solution has always been _"Seemed that application/xml made more sense"_ – a better oliver Sep 01 '16 at 06:37
1

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' }
})
a better oliver
  • 26,330
  • 2
  • 58
  • 66
Skyler
  • 777
  • 1
  • 9
  • 34