alexandernst
alexandernst

Reputation: 15089

POST-ing a raw XML using AngularJS's $resource (v1.2.x)

I'm trying to send some XML via POST to an API, using AngularJS's $resource, but I'm not really sure how I'm supposed to pass the data I want to send.

This is what I have currently:

    "Cart": $resource("http://........../api?ws_key=*********", {
        ws_key: ws_key
    }, {
        save: {
            method: "POST",
            isArray: false,
            headers:{
                'Content-Type':'raw; charset=UTF-8'
            }
        }
    })

Say I want to send a simple string (xml). Where should I pass it?

Upvotes: 0

Views: 1172

Answers (1)

Vincent Elcrin
Vincent Elcrin

Reputation: 101

You could use transformRequest which by default transform the data passed through into json.

"Cart": $resource("http://........../api?ws_key=*********", {
    ws_key: ws_key
}, {
    save: {
        method: "POST",
        isArray: false,
        transformRequest: function transformDataToXml(data, headersGetter) { /* ... */}
        headers:{
            'Content-Type':'application/xml; charset=UTF-8'
        }
    }
})

Then

card.$save("<tab>content</tag>"); 

Upvotes: 2

Related Questions