當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。