当前位置: 首页>>代码示例>>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;未经允许,请勿转载。