locked
Angular 2/4 Put call to asp.net web api RRS feed

  • Question

  • User845241356 posted

    My API controller works fine on POSTMAN. However on the client, 

    I would like to update a record on the sql db using the update method(Angular 2/4) service that recives JSON objects from the component

      update (vehicle:any){
        return this.http.put('/api/vehicles',   + vehicle  )
        .map(res => res.json());

      }

    <sub></sub><sup></sup>

    However this is the error I get... 

    JSON.parse Error: Invalid character at

    Kindly help me find to correctly format my object s

    Tuesday, December 5, 2017 9:53 AM

Answers

  • User283571144 posted

    Hi Deleted,

    I would like to update a record on the sql db using the update method(Angular 2/4) service that recives JSON objects from the component

    According to your code sample, I guess you may use the wrong put url to send the request to web api.

    I found you use  "return this.http.put('/api/vehicles',   + vehicle )" url. In my opinion, the vehicle's value is the parameter in the url.

    So the url is like this:

    return this.http.put('/api/vehicles/',   + vehicle )

    I suggest you could use browser development tool F12 to check the send request's url is as same as the url in the postman.

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 6, 2017 2:57 AM

All replies

  • User283571144 posted

    Hi Deleted,

    I would like to update a record on the sql db using the update method(Angular 2/4) service that recives JSON objects from the component

    According to your code sample, I guess you may use the wrong put url to send the request to web api.

    I found you use  "return this.http.put('/api/vehicles',   + vehicle )" url. In my opinion, the vehicle's value is the parameter in the url.

    So the url is like this:

    return this.http.put('/api/vehicles/',   + vehicle )

    I suggest you could use browser development tool F12 to check the send request's url is as same as the url in the postman.

    Best Regards,

    Brando

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, December 6, 2017 2:57 AM
  • User845241356 posted

    Best regards Brando. Actually you are right it worked after I added +'/' to the PUT url. Thank you very much. May the good Lord bless you

    Wednesday, December 6, 2017 2:31 PM