2017-12-08 26 views
0

Angularcliヘッダ

pushvalueId(paramid: number): Observable<any[]> { 
    let myHeaders = new Headers(); 
    myHeaders.set('ValueID', '77'); 
    let myParams = new URLSearchParams(); 
    myParams.set('ValueID', paramid.toString()); 
    let options = new RequestOptions({ headers: myHeaders, params: myParams }); 
    return this._http.post(this._getreport, options) 
} 

私が最初にやろうとしているのは、自分のクラスのヘッダー値を取得することです。

public int ValueID { get; set; } 
    ValueID = Convert.ToInt32(HttpContext.Current.Request.Headers.GetValues("ValueID")); 

`import { Http, Response, JsonpModule, HttpModule, Headers, RequestOptions } from '@angular/http';` 
+0

はこの 'angular'または'角度-js'ある - RequestOptionsを使用しないでください

this._http.post(this._getreport, null, {headers: myHeaders, params: myParams}) 

:オプションのためには、第3引数を使用する必要がありますか – Aravind

+0

angular2なので角度 – Sevensnake77787

答えて

0

まず、廃止予定のhttpクライアントを使用しています。 '@angular/common/http'

post methodの2番目の引数はbodyです。 ?これらは古いHTTPクライアントの一部であり、deprecated

+0

私はそれを試してみてください。 – Sevensnake77787

+0

私はその変更を行った。 @Martin Nuc.'コンストラクタ(private _http2:HttpClient){} '' ReportId(paramid:any):Observable { let header = new HttpHeaders; header.append( 'Content-Type'、 'application/json'); header.append( 'ValueID'、paramid); myParamsを新しいHttpParams()にします。 myParams.set( 'ValueID'、 '587'); これを返す._http2.post(this._getreport、null、{ヘッダ:ヘッダ、パラメータ:myParams}) ' – Sevensnake77787