ng2 http获取服务器数据的时候传递参数详解
get(url: string,options?: RequestOptionsArgs): Observable<Response>; post(url: string,body: string,options?: RequestOptionsArgs): Observable<Response>; put(url: string,options?: RequestOptionsArgs): Observable<Response>; delete(url: string,options?: RequestOptionsArgs): Observable<Response>; patch(url: string,options?: RequestOptionsArgs): Observable<Response>; head(url: string,options?: RequestOptionsArgs): Observable<Response>;
2、详解
this.http({ url: "data/list.json" or "data/list.PHP" or ...... method: "get",search: "name=zhangxuchao&password=heping" or 使用URLSearchParams() 对象 headers: 使用Headers()对象设置 可选 body: "" 可选 })
3、实例
import { Http,Response,URLSearchParams } from 'angular2/http'; let params = new URLSearchParams(); params.set('name','huge'); console.log(params.toString()) // name=huge this.http.get(StaticSettings.BASE_URL,{ search: params}).subscribe( ); this.http.post(url,params).subscribe(res=> { console.log(res); });
URLSearchParams说明地址:https://developer.mozilla.org...