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


TypeScript Headers.set方法代碼示例

本文整理匯總了TypeScript中@angular/http.Headers.set方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript Headers.set方法的具體用法?TypeScript Headers.set怎麽用?TypeScript Headers.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在@angular/http.Headers的用法示例。


在下文中一共展示了Headers.set方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: writeRequest

    writeRequest(request: IN, options: RequestOptionsArgs): RequestOptionsArgs {

        const opts = new RequestOptions(options).merge({body: JSON.stringify(request)});

        let headers: Headers;

        if (opts.headers) {
            headers = opts.headers;
        } else {
            opts.headers = headers = new Headers();
        }
        headers.set("Content-Type", "application/json");

        return opts;
    }
開發者ID:surol,項目名稱:ng2-rike,代碼行數:15,代碼來源:protocol.ts

示例2: get

 /**
  * Wrapper for HTTP GET operation
  */
 public get(url: string, paramsMap?: Map<any, any>): Observable<any> {
     this._headers.set("Cache-Control", "no-cache");
     let options = new RequestOptions({headers: this._headers});
     if (paramsMap) {
         const requestParams: URLSearchParams = new URLSearchParams();
         paramsMap.forEach((key, value) => {
             requestParams.set(key, value);
         });
         options = new RequestOptions({headers: this._headers, search: requestParams});
     }
     return this._http
         .get(this._baseUrl + url, options)
         .map(response => this.mapResponse(response))
         .catch(error => this.handleError(error));
 }
開發者ID:EduCaMa,項目名稱:Showcase,代碼行數:18,代碼來源:rest-client.service.ts

示例3: doRequest

  private doRequest(resource:string, call_method:APICallMethod, params:Object, need_authorized:boolean)
  {
    if (need_authorized && this.token_ === null) {
      // TODO raise error
      return;
    }

    let full_url = this.url_ + resource;

    let headers = new Headers();
    let options = new RequestOptions();
    options.headers = headers;
    // TODO Optimize condition
    if (call_method == APICallMethod.Post) {
      headers.set("Content-Type", "application/json");
      options.method = RequestMethod.Post;
      let params_json_str = JSON.stringify(params);
      options.body = params_json_str;
    }
    else if (call_method == APICallMethod.Get) {
      headers.set("Content-Type", "");
      options.method = RequestMethod.Get;
      options.body = "";
    }
    else if (call_method == APICallMethod.Delete) {
      headers.set("Content-Type", "text/plain");
      options.method = RequestMethod.Delete;
      options.body = "";
    }
    this.logger_.info("[APIService]doRequest", full_url, call_method);

    return this.http_.request(full_url, options)
      .map(resp => this.extractData(resp))
      .catch(error => this.handleError(error));

  }
開發者ID:future0906,項目名稱:cfblog2_admin_web,代碼行數:36,代碼來源:api_service.ts

示例4: find

    // Array<Flight>, Flight[]
    find(from: string, to: string): Observable<Flight[]> {
        
        let url = "http://www.angular.at/api/flight";
        
        let headers = new Headers();
        headers.set('Accept', 'text/json');

        let search = new URLSearchParams();
        search.set('from', from);
        search.set('to', to);

        return this.http
                    .get(url, { headers,search })
                    .map(resp => resp.json());

    }
開發者ID:manfredsteyer,項目名稱:angular2-performance-immutables,代碼行數:17,代碼來源:flight.service.ts

示例5: find

    public find(from: string, to: string) {
        
        let url = "/data/flights.json";
        
        var search = new URLSearchParams();
        search.set('from', from);
        search.set('to', to);
        
        var headers = new Headers();
        headers.set('Accept', 'text/json');
        
        return this.http
                    .get(url, { search, headers  })
                    .map(resp => resp.json())

    }
開發者ID:manfredsteyer,項目名稱:angular2-sdd-london-2016,代碼行數:16,代碼來源:flight.service.ts

示例6: Promise

    return new Promise(resolve => {
      let url = ApiConfig[url_path];
      
      url = options.id? url + options.id: url;
      url = options.category_id? url + "?category_id=" + options.category_id: url;

      if(options.ids){
        url = url + "?";
        for(let i = 0; i <  options.ids.length; i++) {
            url = url + "id=" + options.ids[i] + "&&";
        }
      }

      let headers = new Headers();
      headers.set('Authorization', "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpc3MiOiIyfHVuZGVmaW5lZCIsInN1YiI6InN1YmplY3QiLCJhdWQiOiJzYWlscy13YXRlcmxvY2stdG9rZW4tdGVtcGxhdGUiLCJleHAiOjE0Njg5ODU4NzYxNzgsIm5iZiI6MTQ2ODM4MTA3NjE3OCwiaWF0IjoxNDY4MzgxMDc2MTc4LCJqdGkiOiIyZmU4ZWIyMC00OGFiLTExZTYtODVkYi1jMTk5ZGI3NDAzYWIifQ.Eey2ffNAdRf179JeEjWg2vizZSR1sQTqmlzneqR3RQU");

      let opt: RequestOptions;
      opt = new RequestOptions({
          headers: headers
      });
      this.http.get(url, opt)
          .map(res => {
            if(res.status < 200 || res.status >= 300) {
              // this.nav.push(LoginPage);
            }
            // If everything went fine, return the response
            else {
              return res.json();
            }
              
          })
          .subscribe(data => {
            console.log(url)
            resolve(data);

          }, err => {
            console.log("Response ERROR:")
            console.log(err);
            // let prompt = Alert.create({
            //   message: JSON.parse(err._body).error,
            //   buttons: [{text: "Ok"}]
            // });
            // this.nav.present(prompt);
            resolve(err);
          });
    });
開發者ID:bkitaec,項目名稱:mytest-app,代碼行數:46,代碼來源:db.ts

示例7: postFile

          //Bekommt als Name die ID des Nutzers auf dem jwt Ăźbergeben, diese wird als Name der Datei verwendet
          //http-Modul von Angular unterstĂźtzt das multipart Format aktuell nicht daher xhr
          postFile(inputValue: any, name: string, pfad:string): void {

            var formData = new FormData();
            formData.append("name", name);
            formData.append("pfad", pfad);
            formData.append("file",  inputValue.files[0]);
            var headers = new Headers();
            headers.set('Content-Type', 'multipart/form-data');

            let xhr = new XMLHttpRequest();

            xhr.open('POST', Path[0]+'/upload', true);
            xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
            xhr.withCredentials = false;
            xhr.send(formData);


        }
開發者ID:SocialMovieNetwork,項目名稱:SMP-Final,代碼行數:20,代碼來源:upload.service.ts

示例8: getAuthHeaders

 getAuthHeaders(): Headers {
     let headers = new Headers({'Content-Type': 'application/x-www-form-urlencoded'});
     headers.set('authorization', this.getToken());
     return headers;
 }
開發者ID:liubo5400,項目名稱:payAdmin,代碼行數:5,代碼來源:base.service.ts

示例9: setAuthorizationHeader

 private setAuthorizationHeader(headers: Headers) {
   headers.set('Authorization', this.authService.getRequestHeaderValue());
 }
開發者ID:dadall,項目名稱:PeerTube,代碼行數:3,代碼來源:auth-http.service.ts

示例10: addAuthorizationData

 public addAuthorizationData(token: string): void {
     this.headers.set("Authorization", "Bearer " + token);
 }
開發者ID:BGligorijevic,項目名稱:pac-front-end,代碼行數:3,代碼來源:header.service.ts


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