How to use the tns-core-modules/http.request function in tns-core-modules

To help you get started, we’ve selected a few tns-core-modules examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github linfaservice / cloudgallery / app / pages / gallery / image-modal.component.ts View on Github external
ngAfterViewInit() {  
    this.loader.hideLoader();

    // load high resolution image in background
    //console.log("Image Loading: " + this.item.url + "/500/500");

    if(!this.item.loaded) {
      Http.request({
          url: this.item.url + "/500/500",
          method: "GET",
          headers: this.headers
      }).then((response:any)=> {

          response.content.toImage()
            .then((image)=> {
              let base64 = image.toBase64String("jpg");
              let highsrc = base64;
              this.item.src = highsrc;
              this.item.loaded = true;
            })
            .catch((error)=> {
              //util.log("error", error);
            });
github linfaservice / cloudgallery / app / pages / gallery / gallery.component.ts View on Github external
this.current.push(item);
        }
        this.updateFooter(this.cache.images[this.cache.currentAlbum.nodeid].totAlbums, 0);
        let data = this.cache.images[this.cache.currentAlbum.nodeid].data;

        // otherwise too fast :)
        timer.setTimeout(()=> { 
          this.loader.hideLoader(); 
          this.scanImages(data.files, nodeid);
        }, 800);

      } else {

        this.util.log("Cache Not Found :( Retrieving from cloud…", null);
      
        Http.request({
            url: url,
            method: "GET",
            headers: this.headers
        }).then((response:any)=> {
            let data = null;

            try {
              data = response.content.toJSON();
            } catch(e) {
              Toast.makeText(this.translate.instant("Error loading. Please retry")).show();
              this.util.log("Error", e);
              this.loader.hideLoader();
              return;              
            }

            if(data==null) {
github NativeScript / NativeScript / tests / app / http / http-tests.ts View on Github external
export var test_request_requestShouldTimeout = function (done) {
    var result;
    http.request({ url: "https://10.255.255.1", method: "GET", timeout: 500 }).catch(function (e) {
        result = e;
        try {
            TKUnit.assert(result instanceof Error, "Result from request().catch() should be Error! Current type is " + typeof result);
            done(null);
        }
        catch (err) {
            done(err);
        }
    });
};
github linfaservice / cloudgallery / app / pages / gallery / gallery.component.ts View on Github external
private loadImages(albumid, item) {
      if(albumid==this.cache.currentAlbum.nodeid) { 
        let filepath = "";
        let filepath_chunk = item.path.split("/");
        for(let c=0; c {

            if(albumid==this.cache.currentAlbum.nodeid) { 
              let imgObj = new GalleryItem();
              response.content.toImage()
                .then((image)=> {
                  let base64 = image.toBase64String();
                  imgObj.src = base64;
                  imgObj.title = filepath_chunk[filepath_chunk.length-1];
                  imgObj.url = imgurlroot;
                  imgObj.mtime = item.mtime;

                  this.current.push(imgObj);
github tralves / groceries-ns-vue / app / services / LoginService.js View on Github external
resetPassword(email) {
    return http.request({
      url: this.baseUrl + "rpc/" + this.appKey + "/" + email + "/user-password-reset-initiate",
      method: "POST",
      headers:this.getCommonHeaders()
    })
    .then(this.validateCode)
    .then(this.getJson)
    .then(data => {
      console.info('Reset password for email: ' + data.Result.Result)
    })
  }
github bradmartin / nativescript-gif / src / gif.android.ts View on Github external
if (value[1] === '/' && (value[0] === '.' || value[0] === '~')) {
          value = value.substr(2);
        }

        if (value[0] !== '/') {
          value = currentPath + '/' + value;
        }

        this._drawable = new pl.droidsonroids.gif.GifDrawable(value);
        this.nativeView.setImageDrawable(this._drawable);
      } else {
        const requestOptions: any = { url: value, method: 'GET' };
        if (this._headers !== null) {
          requestOptions.headers = this._headers;
        }
        HttpRequest(requestOptions).then(
          r => {
            if (r.statusCode === 200) {
              this._drawable = new pl.droidsonroids.gif.GifDrawable(
                r.content.raw.toByteArray()
              );
              this.nativeView.setImageDrawable(this._drawable);
            } else {
              console.log('error getting image: ' + r.statusCode);
            }
          },
          err => {
            console.log(err);
          }
        );
      }
    } else {
github triniwiz / nativescript-stripe / demo-angular / app / demo / stripe.service.ts View on Github external
private _postRequest(endpoint: string, content: string = ''): Promise {
    let url = this._backendURL(endpoint);
    return httpModule.request({
      url: url,
      method: "POST",
      headers: { "Content-Type": "application/x-www-form-urlencoded; charset=utf-8" },
      content
    }).then(response => {
      if (response.statusCode < 200 || response.statusCode >= 300) {
        throw new Error(response.content.toString());
      }
      return response;
    });
  }