當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript Http.request方法代碼示例

本文整理匯總了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)));
 }
開發者ID:TinMarkovic,項目名稱:Dramazon,代碼行數:7,代碼來源:TodoService.ts

示例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;
                 }
             });
 }
開發者ID:acndavidd,項目名稱:iDSP-testAPI,代碼行數:31,代碼來源:my-http.service.ts

示例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);
    });
  }
開發者ID:AdrianPasalega,項目名稱:mean-blueprints-ecommerce,代碼行數:25,代碼來源:auth-http.ts

示例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);
    }
開發者ID:codetunez,項目名稱:electron-skeleton,代碼行數:8,代碼來源:home.ts

示例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;
         });
 }
開發者ID:dejan-apaone,項目名稱:tut7,代碼行數:17,代碼來源:route-component.ts

示例6: all

 all(url:string) {
     var options = new RequestOptions({
         method: RequestMethod.Get,
         url: url
     });
     var req = new Request(options);
     return this.http.request(req);
 }
開發者ID:atexo-package,項目名稱:atexo-component-dashboard,代碼行數:8,代碼來源:panel-body-article.provider.ts

示例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;
     });
 }
開發者ID:Gitjerryzhong,項目名稱:angular2,代碼行數:8,代碼來源:SimpleHTTPComponent.ts

示例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);
    }
開發者ID:drommc,項目名稱:ng2-ui-auth,代碼行數:8,代碼來源:local.ts

示例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);
 }
開發者ID:drommc,項目名稱:ng2-ui-auth,代碼行數:8,代碼來源:oauth.ts

示例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());
    }
開發者ID:amitmahida92,項目名稱:angular-2-sample-rra,代碼行數:9,代碼來源:listIssues.service.ts


注:本文中的angular2/http.Http.request方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。