Sox -
Sox -

Reputation: 612

Angular post request expect a GET

I have a simple function that cannot be processed, here is the ts code.

update(accNode: CcAccNode): Observable<any> {
  return this.http.post<CcAccNode>('/api/core_component/acc/' + accNode.accId, {
    'objectClassTerm': accNode.objectClassTerm,
    'state': accNode.state,
    'den': accNode.den,
    'definition': accNode.definition,
    'is_abstract': accNode.abstracted,
    'is_deprecated': accNode.deprecated,
  });
}

The logs give me this kind of response :

Request URL: http://localhost:4200/api/core_component/acc/8150
Request Method: POST
Status Code: 405 Method Not Allowed
Remote Address: 127.0.0.1:4200
Referrer Policy: no-referrer-when-downgrade

Access-Control-Allow-Origin: *
allow: GET

How to bypass that ? Thanks you !

Upvotes: 2

Views: 83

Answers (3)

Sox -
Sox -

Reputation: 612

Thanks for all your response, there was a SQL typo in the backend, I thought maybe it was located on the front but as Hjbello told me it was a Backend problem ! Thanks again guys !! :)

Upvotes: 1

firegloves
firegloves

Reputation: 5709

You are making a POST but your service expects a GET request. You need something like this

update(accNode: CcAccNode): Observable<any> {
  return this.http.get<CcAccNode>('/api/core_component/acc/' + accNode.accId +
    '?objectClassTerm=' + accNode.objectClassTerm +
    'state=' +  accNode.state +
    'den=' +  accNode.den +
    'definition=' +  accNode.definition +
    'is_abstract=' +  accNode.abstracted +
    'is_deprecated=' +  accNode.deprecated
  );
}

Upvotes: 3

hjbello
hjbello

Reputation: 651

I am not very sure but I believe that you have not added the url correctly. It seems as you are posting to you own front-end server:

http://localhost:4200/api/core_component/acc/8150´

and I do not know if it is what you want. when you do

return this.http.post<CcAccNode>('/api/core_component/acc/' + accNode.accId, {...})

perhaps you should replace

'/api/core_component/acc/'

with

yourBackendBaseUrl + '/api/core_component/acc/'

Upvotes: 2

Related Questions