0

I am trying to post json to an api and its giving me the following error...

http://www.website.com/getPriceNoAuth?json=[object%20Object] 405 (Method Not Allowed)

This is the json object I am trying to send and its http resuest...

var productAttributes = {
    "CostRequirements":[
        {
            "OriginPostcode":"BR60ND",
            "BearerSize":100,
            "BandwidthRequired":10,
            "ProductCode":"CON-ELA",
            "Term":36,
            "Quantity":1
        },
        {
            "ProductCode":"CON-ADD-IP4",
            "Term":36,
            "Quantity":0
        },
        {
            "ProductCode":"CON-ADD-INT",
            "Term":36,
            "Quantity":0
        }
    ]
}

this.getPrices1 = function () {
    return $http.post('http://www.website.com/getPriceNoAuth?json=' + productAttributes ).
        success(function(resp){
            //log something here.
        });
};

Does anyone see what I'm doing wrong? thank you.

0

4 Answers 4

1
$http({
url:'http://myurl.com'
method:'POST',
data:{
  'json':productAttributes
}
});

ORRR if you really need to pass the data from the url stringify your json and decode it on server side

$http.post('http://myurl.com?json=' + JSON.stringify(myJson));
Sign up to request clarification or add additional context in comments.

2 Comments

@LeeWillis i don't know the user needs, maybe he need it are you a clairvoyant ? :)
Its just a small amount of data for an internal application. You're soloution worked for me. Thank you
0

You're trying to post the data, but you're putting it in the url like a get parameter. Post data like this:

this.getPrices1 = function () {
    return $http.post('http://www.website.com/getPriceNoAuth', {json: productAttributes} ).
        success(function(resp){
            //log something here.
        });
};

Comments

0

The http header are not defined in there.. but by defaults it considers json as the content type:

$http.post('/someUrl', data).success(successCallback);

Comments

0

here you have to call an api, in which we have to sent data using get method. Just use the following code and that's it. It works for me, hope it will work for you also.

var dataObject = {
    json : productAttributes
};


var responsePromise = $http.get("http://www.website.com/getPriceNoAuth", dataObject, {});

responsePromise.success(function(dataFromServer, status, headers, config) {

    var outputDate=angular.fromJson(dataFromServer);

    if(outputDate.status==1)
    {
        angular.forEach(outputDate.storelist, function(value, key) {
            $scope.userstores.push({name:value.StoreName,id:value.StoreID});
        });
    }          
});

responsePromise.error(function(data, status, headers, config) {
    console.log("Error in fetching user store call!");
});

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.