Angular2将字符串参数传递给PUT webapi null

时间:2018-03-19 14:36:50

标签: angular asp.net-web-api

我在asp.net核心中有一个webapi,动作方法定义是

[HttpPut("{id}")]
public async Task<IActionResult> UpdateCaseStatus(int id, [FromBody] string status)
{

}

当我尝试从我的angular2应用程序调用此方法时,字符串值始终为null。谁能帮助我,我在这里做错了什么?

这是我在angular2 app中的方法:

  let url = `${this.config.ApiUrl}/api/cases/${this.trader.id}`;
  this.authService.AuthPut(url, 'OPENED')

AuthPut(url: string, data: any, options?: RequestOptions): Observable<Response> {
    let body = JSON.stringify(data);

    if (options) {
        options = this._setRequestOptions(options);
    } else {
        options = this._setRequestOptions();
    }
    return this.http.put(url, body, options);
}

private _setAuthHeaders(user: any): void {
    this.authHeaders = new Headers();
    this.authHeaders.append('Authorization', this.getAuthorizationHeaderValue());
    if (this.authHeaders.get('Content-Type')) {

    } else {
        this.authHeaders.append('Content-Type', 'application/json;');
        this.authHeaders.append('Accept', 'application/json');
    }
}

private _setRequestOptions(options?: RequestOptions) {
    if (this.isLoggedIn) {
        this._setAuthHeaders(this.user);
    }
    if (options) {
        options.headers.append(this.authHeaders.keys[0], this.authHeaders.values[0]);
    } else {
        options = new RequestOptions({ headers: this.authHeaders, body: '', method: 'GET' });
    }

    return options;
}

0 个答案:

没有答案