json - Angular2 how to correct put request -
ok then, have single problem,
request url:http://.../rest/1.0/brand/test145 request method:put status code:500 internal server error remote address:...
request payload ok { "name": "test145" }
addbrand(name : string){ let body = json.stringify(name) let url = this.baseurl + '/brand/' + name; return this.http.put(url, { name } ). map(res => res.json()); } addbrand(name:any){ if(!name){return;} this.brandservice.addbrand(name) .subscribe( name => this.name.push(name), error => this.errormesage = <any>error); }
but put should http://.../rest/1.0/brand/ , then, should request payload. when remove "name" from, doesn't load payload.
stricly put update, url should in format:
http://.../rest/1.0/brand/test145 last part unique id (you need indicate mean update)
if expect create record, should rather post http://.../rest/1.0/brand
but can choose deviate conventions. in order put .../brand
payload { "name": "test145" }
need to:
addbrand(name : string){ let body = json.stringify({ name: name }) let url = this.baseurl + '/brand' return this.http.put(url, body ). map(res => res.json()); }
Comments
Post a Comment