私のPOSTエンドポイント(ASP.NET WebAPI)を角度2のHTTPサービスから呼び出そうとしていますが、エンドポイントが全くヒットしません。私はすでにいくつかの投稿を読んでいるが、それらのどれもまだ働いていない。角度2 - 予期しないトークン<0のJSONで - WebAPI [HttpPost]
私の角度2の成分から、私はauctionserviceで
saveCarAuction(): void {
let respone: ResponseObject;
this.auctionservice.saveCarAuction(this.auction).subscribe(resp => {
respone = resp;
}, error => this.onError(error));
}
ように私のサービスを呼び出しています、私は私のウェブAPIコントローラで
saveCarAuction(auction: CarAuction): Observable<ResponseObject> {
let headers = new Headers({ 'Content-Type': 'application/json' });
let options = new RequestOptions({ headers: headers });
var api: string = '/CarAuction';
var url: string = this.baseApiPath + api;
return this.http.post(url, JSON.stringify(auction), options)
.map((res: Response) => res.json());
}
を持って、私は
[HttpPost]
[Route("api/CarAuction")]
[ActionName("PostCarAuction")]
public IHttpActionResult PostCarAuction([FromBody]CarAuctionViewModel carAuction)
{
ResponseObject response = new ResponseObject() {ResponseType = ResponseType.Success.ToString()};
//some action
return Ok(Utility.SerializeObject(response));
}
を持っています私のサービスコールの最終的なURLは
ですhttp://localhost:53796/api/CarAuction
問題は、私のアクションにブレークポイントを置くと、呼び出されないということです。 (私はそれを好まないが)
JSON.stringify({ carAuction: auction})
私もルーティング属性を経由して、それを呼び出そうとしていますが、それはどちらか動作していない:私は以下のように私のサービスとは異なるデータを渡すためにしようとしています。私はポストアクションでシンプルなjsonストリングを受け取り、デシリアライズして戻り値のタイプを更新しようとしましたが、トリッキーなゲームをすることに決めました。私のコンソールで
すべての要求(および変更)の応答は、私は本当にこの単純なシナリオを正常に実行するために、今のアイデアを使い果たしている
を下回っています。
EDIT 1: 私はあなたがnetwork tabを使用してサーバからの応答をチェックして、あなたの質問にそれを追加する必要があり、私のAPIに
{
"carAuction": {
"carPlateNumber": null,
"carAuctionId": null,
"sellerUserId": null,
"carMakeId": null,
"carModelId": null,
"carColorId": null,
"carType": null,
"manufacturerYear": 2002,
"manufacturerMonth": 4,
"carMileage": 475000,
"ownershipCount": 3,
"ownershipType": null,
"comments": null,
"notes": null,
"terms": null,
"coverPhotoUrl": null,
"salePublicationDateTime": null,
"saleEndDateTime": null,
"auctionType": null,
"carbidPercentage": null,
"saleType": null,
"isHiddenAuction": false,
"intervalBid": 0,
"minimumPrice": 0,
"contactPersonFullName": null,
"contactPersonCompany": null,
"contactPersonPhone": null,
"contactPersonFax": null,
"contactPersonWebsite": null,
"contactPersonEmail": null,
"contactPersonAddress": null,
"hasAuctionEnded": false,
"carLocation": null,
"carMake": null,
"carModel": null,
"carColor": null,
"carAuctionMedia": [],
"id": "3F8184F7-37F4-4BD9-8B32-FDB8F65D5AB3",
"appCultureId": null,
"createdDate": null,
"createdBy": null,
"isActive": true,
"modifiedDate": null,
"modifiedBy": null
}
}
'auction'値を共有すると、' saveCarAuction'関数の中に入っていますか? – ranakrunal9
JSON.stringify({carAuction:auction})、その有効なJSON –
@AliBaig baseApiPathとは何ですか? – Milad