Http post request with raw json body


#1

I am trying to do an http request that sends raw json to an api end point. I am having success in postman but in NS app i am having error.

This is my snippet:

    return http.request({
        url: config.apiUrl2+'Registration/RegisterIndividual', 
        method: "POST",
        headers: {"Content-Type":"application/json; charset=utf8"},
        body: {"PrimaryUser": {"Email":"leo"}},
        json: true
    }).then(
        function(r){
            console.dir(r);
            return r;
        }, function(e){
            handleErrors(e);
    })

This is the response I am seeing:

        {
        JS:     "content": {
        JS:         "Message": "An error has occurred."
        JS:     },
        JS:     "statusCode": 500,
        JS:     "headers": {
        JS:         "null": "HTTP/1.1 500 Internal Server Error",
        JS:         "Cache-Control": "no-cache",
        JS:         "Content-Length": "36",
        JS:         "Content-Type": "application/json; charset=utf-8",
        JS:         "Date": "Sat, 18 Nov 2017 13:09:55 GMT",
        JS:         "Expires": "-1",
        JS:         "Pragma": "no-cache",
        JS:         "Server": "Microsoft-IIS/8.5",
        JS:         "X-Android-Received-Millis": "1511010595024",
        JS:         "X-Android-Response-Source": "NETWORK 500",
        JS:         "X-Android-Selected-Protocol": "http/1.1",
        JS:         "X-Android-Sent-Millis": "1511010594881",
        JS:         "X-AspNet-Version": "4.0.30319",
        JS:         "X-Powered-By": "ASP.NET"
        JS:     }
        JS: }

#2

@jessiPP
Try this
https://docs.nativescript.org/cookbook/http#post-json


#3

Thank you so much this solved the issue.