当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript http.request函数代码示例

本文整理汇总了TypeScript中tns-core-modules/http.request函数的典型用法代码示例。如果您正苦于以下问题:TypeScript request函数的具体用法?TypeScript request怎么用?TypeScript request使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了request函数的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: function

export var test_request_responseStatusCodeShouldBeDefined = function (done) {
    var result: http.HttpResponse;

    // >> http-get-response
    http.request({ url: "https://httpbin.org/get", method: "GET" }).then(function (response) {
        //// Argument (response) is HttpResponse!
        var statusCode = response.statusCode;
        // >> (hide)
        result = response;
        try {
            TKUnit.assert(typeof (result.statusCode) !== "undefined", "response.statusCode should be defined!");
            done(null);
        }
        catch (err) {
            done(err);
        }
        // << (hide)
    }, function (e) {
        //// Argument (e) is Error!
        // >> (hide)
        done(e);
        // << (hide)
    });
    // << http-get-response
};
开发者ID:sitefinitysteve,项目名称:NativeScript,代码行数:25,代码来源:http-tests.ts

示例2: function

export var test_request_FormDataContentSentAndReceivedProperly = function (done) {
    var result;

    var data = new FormData();
    data.append("MyVariableOne", "ValueOne");
    data.append("MyVariableTwo", "ValueTwo");

    http.request({
        url: "https://httpbin.org/post",
        method: "POST",
        headers: { "Content-Type": "application/x-www-form-urlencoded" },
        content: data
    }).then(function (response) {
        result = response.content.toJSON();
        try {
            TKUnit.assert(result["form"]["MyVariableOne"] === "ValueOne" && result["form"]["MyVariableTwo"] === "ValueTwo", "Content not sent/received properly!");
            done(null);
        }
        catch (err) {
            done(err);
        }
    }, function (e) {
        done(e);
    });
};
开发者ID:m-abs,项目名称:NativeScript,代码行数:25,代码来源:http-tests.ts

示例3: _setSrcProperty

  private _setSrcProperty(value: string) {
    if (value) {
      value = value.trim();
      let isUrl = false;

      if (value.indexOf('://') !== -1) {
        if (value.indexOf('res://') === -1) {
          isUrl = true;
        }
      }
      this._src = value;
      if (!isUrl) {
        const currentPath = knownFolders.currentApp().path;

        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 {
      console.log('No src property set for the Gif.');
    }
  }
开发者ID:bradmartin,项目名称:nativescript-gif,代码行数:49,代码来源:gif.android.ts


注:本文中的tns-core-modules/http.request函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。