• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript http.request函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1:

(() => {
    const tunnelingAgent = tunnel.httpOverHttps({
        maxSockets: poolSize, // Defaults to http.Agent.defaultMaxSockets

        proxy: { // Proxy settings
            host: proxyHost, // Defaults to 'localhost'
            port: proxyPort, // Defaults to 443
            localAddress, // Local interface if necessary

            // Basic authorization for proxy server if necessary
            proxyAuth: 'user:password',

            // Header fields for proxy server if necessary
            headers: {
                'User-Agent': 'Node'
            },

            // CA for proxy server if necessary
            ca: [ fs.readFileSync('origin-server-ca.pem')],

            // Server name for verification if necessary
            servername: 'example.com',

            // Client certification for proxy server if necessary
            key: fs.readFileSync('origin-server-key.pem'),
            cert: fs.readFileSync('origin-server-cert.pem'),
        }
    });

    const req = http.request({
        host: 'example.com',
        port: 80,
        agent: tunnelingAgent
    });
})();
开发者ID:AbraaoAlves,项目名称:DefinitelyTyped,代码行数:35,代码来源:tunnel-tests.ts


示例2: Promise

 await new Promise((resolve) => {
   const reqData = "name is sparky";
   const req = request(
     {
       socketPath: runtime.metadata.socketPath,
       path: "/",
       method: "post",
       headers: {
         "Content-Type": "gibber/ish",
         "Content-Length": reqData.length,
       },
     },
     (res) => {
       let data = "";
       res.on("data", (chunk) => (data += chunk));
       res.on("end", () => {
         expect(JSON.parse(data).type).to.deep.equal("Buffer");
         expect(JSON.parse(data).data.length).to.deep.equal(14);
         resolve();
       });
     }
   );
   req.write(reqData);
   req.end();
 });
开发者ID:firebase,项目名称:firebase-tools,代码行数:25,代码来源:functionsEmulatorRuntime.spec.ts


示例3:

 process.on("exit", () => {
     http.request({
         port: 3001,
         path: "/" + name,
         method: "DELETE"
     }).end();
 });
开发者ID:herrmanno,项目名称:proxy,代码行数:7,代码来源:client.ts


示例4: Headers

      ngZome.run(() => {

        nodeReq = http.request(reqInfo, (res: http.IncomingMessage) => {
          let body = '';
          res.on('data', (chunk) => body += chunk);

          let status = res.statusCode;
          let headers = new Headers(res.headers);
          let url = res.url;

          res.on('end', () => {
            let responseOptions = new ResponseOptions({body, status, headers, url});
            let response = new Response(responseOptions);

            if (utils.isSuccess(status)) {
              ngZome.run(() => {
                responseObserver.next(response);
              });
              ngZome.run(() => {
                responseObserver.complete();
              });
              return;
            }
            ngZome.run(() => {
              responseObserver.error(response);
            });
          });
        });
      })
开发者ID:ldenman,项目名称:universal,代码行数:29,代码来源:node_http.ts


示例5: checkWebsiteIsRunning

function checkWebsiteIsRunning() {

    //The url we want is: 'www.random.org/integers/?num=1&min=1&max=10&col=1&base=10&format=plain&rnd=new'
    const options: http.RequestOptions = {
        host: 'localhost',
        port: 4200,
        path: '/'
    };

    const callback = function (response: http.IncomingMessage) {
        let content = '';

        //another chunk of data has been recieved, so append it to `str`
        response.on('data', function (chunk) {
            content += chunk;
        });

        //the whole response has been recieved, so we just print it out here
        response.on('end', function () {
            if (content.indexOf('<title>Croquet Australia Admin Website</title>') < 0) {
                console.log('Website content does not include expected title');
                console.log(content);
                throw new Error('Website is not running');
            }
            console.log('Website is running');
        });
    }

    http.request(options, callback).end();
}
开发者ID:croquet-australia,项目名称:croquet-australia-admin-website,代码行数:30,代码来源:configure-iis.ts


示例6: sender

    public static sender(payload: string, config) {
        var headers = {
            'Content-Type': 'application/json',
            'Content-Length': payload.length,
        };

        var endpointUrl = config.endpointUrl();
        if (endpointUrl && endpointUrl.indexOf("//") === 0) {
            // add http protocol if the config did not specify https
            endpointUrl = "http:" + endpointUrl;
        }

        var options = {
            host: url.parse(endpointUrl).hostname,
            path: url.parse(endpointUrl).pathname,
            method: 'POST',
            headers: headers
        };

        var req = http.request(options, (res) => {
            res.setEncoding('utf-8');

            //returns empty if the data is accepted
            var responseString = '';
            res.on('data', (data) => {
                responseString += data;
            });
            res.on('end', () => {
            });
        });

        req.write(payload);
        req.end();
    }
开发者ID:UIKit0,项目名称:AppInsights-node.js,代码行数:34,代码来源:Sender.ts


示例7: _getNpmPackageJson

/**
 * Get the NPM repository's package.json for a package. This is p
 * @param {string} packageName The package name to fetch.
 * @param {LoggerApi} logger A logger instance to log debug information.
 * @returns {Observable<JsonObject>} An observable that will put the pacakge.json content.
 * @private
 */
function _getNpmPackageJson(
  packageName: string,
  logger: logging.LoggerApi,
): Observable<JsonObject> {
  const url = `http://registry.npmjs.org/${packageName.replace(/\//g, '%2F')}`;
  logger.debug(`Getting package.json from ${JSON.stringify(packageName)}...`);

  let maybeRequest = npmPackageJsonCache.get(url);
  if (!maybeRequest) {
    const subject = new ReplaySubject<JsonObject>(1);

    const request = http.request(url, response => {
      let data = '';
      response.on('data', chunk => data += chunk);
      response.on('end', () => {
        try {
          const json = JSON.parse(data);
          subject.next(json as JsonObject);
          subject.complete();
        } catch (err) {
          subject.error(err);
        }
      });
      response.on('error', err => subject.error(err));
    });
    request.end();

    maybeRequest = subject.asObservable();
    npmPackageJsonCache.set(url, maybeRequest);
  }

  return maybeRequest;
}
开发者ID:iwe7,项目名称:devkit,代码行数:40,代码来源:npm.ts


示例8: reject

  return new Promise<string>((resolve, reject) => {
    let unexpectedEnd = () => {
      reject({code: 'UNKNOWN', message: 'Request ended unexpectedly'});
    };
    let req = http.request(
        {port: parseInt(port), method: method, path: path, headers: headers}, (res) => {
          req.removeListener('end', unexpectedEnd);
          if (res.statusCode !== 200) {
            reject({code: res.statusCode, message: res.statusMessage});
          } else {
            let buffer: (string|Buffer)[] = [];
            res.on('data', buffer.push.bind(buffer));
            res.on('end', () => {
              resolve(buffer.join('').replace(/\0/g, ''));
            });
          }
        });

    if (timeout) {
      req.setTimeout(timeout, () => {
        reject({code: 'TIMEOUT', message: 'Request timed out'});
      });
    }
    req.on('error', reject);
    req.on('end', unexpectedEnd);

    if (hasContent) {
      req.write(data as string);
    }

    req.end();
  });
开发者ID:sjelin,项目名称:webdriver-manager,代码行数:32,代码来源:utils.ts


示例9: reject

            worker.request = new Promise<PhantomResult>((resolve, reject) => {
                const hmac = crypto.createHmac("sha256", worker.key)
                    .update([worker.counter, 'POST', '/', `localhost:${worker.port}`, 'application/json', payload].join('\n'))
                    .digest('hex');

                http.request({
                    port:    worker.port,
                    method:  'POST',
                    auth:    worker.counter + ':' + hmac,
                    headers: {
                        'Content-Type':   'application/json',
                        'Content-Length': payload.length,
                    },
                }, (response) => {
                    let result = '';

                    response.on('error', (error) => {
                        reject(error);
                    });

                    response.on('data', (data) => {
                        result += data;
                    });

                    response.on('end', () => {
                        resolve([response, result]);
                    });
                })
                .on('error', (error) => {
                    reject(error);
                })
                .end(payload);
            });
开发者ID:LeviticusMB,项目名称:ghostly,代码行数:33,代码来源:ghostly.ts



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript http.ClientRequest类代码示例发布时间:2022-05-25
下一篇:
TypeScript http.get函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap