本文整理汇总了TypeScript中angular2/http.Http.request方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Http.request方法的具体用法?TypeScript Http.request怎么用?TypeScript Http.request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类angular2/http.Http
的用法示例。
在下文中一共展示了Http.request方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: fetchTodos
private fetchTodos(){
let request = this.http.request("/api/TodoItems");
request.subscribe((response: Response) => {
this.todos = response.json().map(todo => new TodoItem(todo.Value, todo.Done, todo.ID))
}, (error) => alert("Error: " + JSON.stringify(error)));
}
示例2: executeRequest
public executeRequest(pObserver, pOpt: RequestOptions) {
console.log('Start request to ' + pOpt.url);
let vCurrentContext = this;
vCurrentContext._modalService.showErrorModal('Start request to ' + pOpt.url);
this._http.request(new Request(pOpt))
.timeout(this.vTimeout, {status: 408})
.subscribe(
(res) => {
pObserver.next(res);
pObserver.complete();
},
(err) => {
switch (err.status) {
case 403:
// caused by invalid token sent to server
// try access once again using refresh token
// if still failed redirect to login page
pObserver.error(err);
break;
case 400: // system error
pObserver.error(err.json());
break;
case 500: // functional error
pObserver.error(err);
default:
// throw error
pObserver.error(err);
break;
}
});
}
示例3: request
private request(requestArgs: RequestOptionsArgs, additionalArgs?: RequestOptionsArgs) {
let opts = new RequestOptions(requestArgs);
if (additionalArgs) {
opts = opts.merge(additionalArgs);
}
let req:Request = new Request(opts);
if (!req.headers) {
req.headers = new Headers();
}
if (!req.headers.has('Authorization')) {
req.headers.append('Authorization', `Bearer ${this.getToken()}`);
}
return this._http.request(req).catch((err: any) => {
if (err.status === 401) {
this.unauthorized.next(err);
}
return Observable.throw(err);
});
}
示例4: constructor
constructor(private http: Http) {
let opts = new RequestOptions({ method: 'GET' });
this.http.request('http://127.0.0.1:4001/api/ping', opts)
.map(x => x.json())
.subscribe(res => this.apiPing = res.ping);
}
示例5: ngOnInit
//http://jsonplaceholder.typicode.com/
// makeRequest():void {
// this.loading = true;
// this.http.request('http://jsonplaceholder.typicode.com/users')
// .subscribe((res:Response) => {
// this.data = res.json();
// this.loading = false;
// });
// }
ngOnInit():any {
this.loading = true;
this.http.request('http://localhost:3000/data/test-users.json')
.subscribe((res:Response) => {
this.data = res.json();
this.loading = false;
});
}
示例6: all
all(url:string) {
var options = new RequestOptions({
method: RequestMethod.Get,
url: url
});
var req = new Request(options);
return this.http.request(req);
}
示例7: makeRequest
makeRequest(): void {
this.loading = true;
this.http.request('http://jsonplaceholder.typicode.com/posts/1')
.subscribe((res: Response) => {
this.data = res.json();
this.loading = false;
});
}
示例8: signup
signup(user, opts?: RequestOptionsArgs): Observable<Response> {
opts = opts || {};
let url = opts.url ? opts.url : joinUrl(this.config.baseUrl, this.config.signupUrl);
opts.body = JSON.stringify(user) || opts.body;
opts.method = opts.method || 'POST';
return this.http.request(url, opts);
}
示例9: unlink
unlink(provider: string, opts: RequestOptionsArgs) {
opts = opts || {};
let url = opts.url ? opts.url : joinUrl(this.config.baseUrl, this.config.unlinkUrl);
opts.body = JSON.stringify({ provider: provider }) || opts.body;
opts.method = opts.method || 'POST';
return this.http.request(url, opts);
}
示例10: deleteIssue
deleteIssue(id) {
let firstHeaders = new Headers();
firstHeaders.append('Content-Type', 'text/plain;charset=UTF-8');
return this.http.request(new Request({
method: APIS.HTTP_METHODS.GET,
url: APIS.DELETE_ISSUE + id
})).map(res => res.json());
}