0

First to say, when I enter the put command in POSTMAN (its then a POST there) I have no problems. Trying to execute the PUT command in code I receive a http 405 error.

The exact error is:

<p>Problem accessing /api/portfolio/createTransaction. Reason:
<pre>    Method Not Allowed</pre></p><hr>

This is my code:

const app = angular.module('demoAppModule', ['ui.bootstrap']);
const apiBaseURL = "/api/portfolio/";

console.log(apiBaseURL);

app.controller('DemoAppController', function($scope, $http) {

    const demoApp = this;

    demoApp.createTransaction = function () {

        console.log("Initiating createTransaction...")

        var transactionDetails = $.param({
                Reference: $scope.reference,
                Quantity: $scope.quantity,
                TradeDate: $scope.tradeDate,
        });

        const createTransactionURL =
            apiBaseURL
            + "createTransaction";

        console.log("Executing flow");
        console.log("Transaction URL = " + createTransactionURL);
        console.log("Transaction Details = " + transactionDetails);

        $http.put(createTransactionURL, angular.toJson(transactionDetails))
        .then(function (transactionDetails, status, headers){
            $scope.ServerResponse = transactionDetails;
        })
        .catch(function (transactionDetails, status, header, config) {
            $scope.ServerResponse =  htmlDecode("transactionDetails: " + transactionDetails +
                "\n\n\n\nstatus: " + status +
                "\n\n\n\nheaders: " + header +
                "\n\n\n\nconfig: " + config);
        });

    };

});

Appreciate any help!

1 Answer 1

1

The server is rejecting your request, likely because it doesn't allow PUT requests. It's probably expecting a HTTP POST instead of a PUT.

If so, change $http.put to $http.post - the method signatures are identical.

If you think the server should be accepting a PUT, you'll need to check why the server side code is rejecting it, which won't be apparent in the client code

Sign up to request clarification or add additional context in comments.

1 Comment

Putting a POST insetead a PUT receives in just nothing. There are no logs in the explorers console or whatever. An additional error (or maybe the cause of 405, I dont know...) is "XML processing error: No root element found"... Im not sure why

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.