spring mvc - Angular 2 Http post call returning reponse status 406 error while calling java controller -
while doing http post call using angular2 java rest controller. keep getting exception saying response status : 406 - not acceptable.
here service.ts code
searchbac(vendorrequest : vendorrequest) : observable<vendorrequest>{ console.log('sending vendor request : ', vendorrequest); if (typeof vendorrequest.bac != 'undefined' && vendorrequest.bac) { console.log('bac certification url :' + this.bacurl); } let bodystring = json.stringify(vendorrequest); // stringify payload console.log("bodystring: " +bodystring) let headers = new headers({ 'content-type': 'application/json' }); console.log("headers:" +headers.get('content-type')); let options = new requestoptions`enter code here`({ method : requestmethod.post, headers: headers.arguments }); // create request option return this.http.post(this.bacurl, bodystring, options).map((res: response) => res.json()) .catch((error : observable<any>) => observable.throw(error)); }
and javacontroller code
@requestmapping(value ="/vendor", method= requestmethod.post, produces = mediatype.application_json_value) public @responsebody vendorrequest getvendordetails(@requestbody vendorrequest vendorrequest) throws exception{ log.info("processing vendor-search request" +vendorrequest.getbaccode()); //vendorrequest vendorrequest = new vendorrequest(); int baccode = vendorrequest.getbaccode(); log.info(baccode+ "obtained request"); vendorrequest.setresponse("success"); log.info("vendorresponse object created , sending"); //objectwriter ow = new objectmapper().writer().withdefaultprettyprinter(); //string jsonstring = ow.writevalueasstring(vendorrequest); return vendorrequest; }
please suggest me changes
Comments
Post a Comment