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


TypeScript ClientRequest.end方法代码示例

本文整理汇总了TypeScript中http.ClientRequest.end方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ClientRequest.end方法的具体用法?TypeScript ClientRequest.end怎么用?TypeScript ClientRequest.end使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在http.ClientRequest的用法示例。


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

示例1: resolve

 return new Promise<void>((resolve, reject) => {
     let parsedUrl: url.Url = url.parse(urlString);
     let request: ClientRequest = https.request({
         host: parsedUrl.host,
         path: parsedUrl.path,
         agent: util.GetHttpsProxyAgent(),
         rejectUnauthorized: vscode.workspace.getConfiguration().get("http.proxyStrictSSL", true)
     }, (response) => {
         if (response.statusCode == 301 || response.statusCode == 302) {
             let redirectUrl: string | string[];
             if (typeof response.headers.location === "string") {
                 redirectUrl = response.headers.location;
             } else {
                 redirectUrl = response.headers.location[0];
             }
             return resolve(downloadCpptoolsJson(redirectUrl)); // Redirect - download from new location
         }
         if (response.statusCode != 200) {
             return reject();
         }
         let downloadedBytes = 0; // tslint:disable-line
         let cppToolsJsonFile: fs.WriteStream = fs.createWriteStream(util.getExtensionFilePath("cpptools.json"));
         response.on('data', (data) => { downloadedBytes += data.length; });
         response.on('end', () => { cppToolsJsonFile.close(); });
         cppToolsJsonFile.on('close', () => { resolve(); });
         response.on('error', (error) => { reject(); });
         response.pipe(cppToolsJsonFile, { end: false });
     });
     request.on('error', (error) => { reject(); });
     request.end();
 });
开发者ID:appTimesTV,项目名称:vscode-cpptools,代码行数:31,代码来源:abTesting.ts

示例2: getHttpsProxyAgent

 return new Promise<void>((resolve, reject) => {
     let parsedUrl: url.Url = url.parse(urlStr);
     let request: ClientRequest = https.request({
         host: parsedUrl.host,
         path: parsedUrl.path,
         agent: getHttpsProxyAgent(),
         rejectUnauthorized: vscode.workspace.getConfiguration().get('http.proxyStrictSSL', true),
         headers: headers
     }, (response) => {
         if (response.statusCode === 301 || response.statusCode === 302) { // If redirected
             // Download from new location
             let redirectUrl: string;
             if (typeof response.headers.location === 'string') {
                 redirectUrl = response.headers.location;
             } else {
                 redirectUrl = response.headers.location[0];
             }
             return resolve(downloadFileToDestination(redirectUrl, destinationPath, headers));
         }
         if (response.statusCode !== 200) { // If request is not successful
             return reject();
         }
         // Write file using downloaded data
         let createdFile: fs.WriteStream = fs.createWriteStream(destinationPath);
         createdFile.on('finish', () => { resolve(); });
         response.on('error', (error) => { reject(error); });
         response.pipe(createdFile);
     });
     request.on('error', (error) => { reject(error); });
     request.end();
 });
开发者ID:swyphcosmo,项目名称:vscode-cpptools,代码行数:31,代码来源:common.ts

示例3: runPostRequest

function runPostRequest(host:string, path:string, body:string, callback:(ClientResponse)=>void) {
    const options = {
        hostname: host,
        port: 3000,
        path: path,
        method: 'POST',
        headers: {
            'Content-Type': 'text/plain',
            'Content-Length': Buffer.byteLength(body)
        }
    };
    let request:ClientRequest = http.request(options, callback);
    request.on('error', traceErrorIfPresent);
    var splittedBody:Array<string> = body.split('');
    while (splittedBody.length > 0) {
        request.write(splittedBody.splice(0, 15).join(''));
    }
    request.end();
}
开发者ID:jan-osch,项目名称:nodexplore,代码行数:19,代码来源:simple-server.js.ts

示例4:

    let req: http.ClientRequest = new http.ClientRequest("https://www.google.com");
    req = new http.ClientRequest(new url.URL("https://www.google.com"));
    req = new http.ClientRequest({ path: 'http://0.0.0.0' });
    req = new http.ClientRequest({ setHost: false });

    // header
    req.setHeader('Content-Type', 'text/plain');
    const bool: boolean = req.hasHeader('Content-Type');
    const headers: string[] = req.getHeaderNames();
    req.removeHeader('Date');

    // write
    const chunk = Buffer.alloc(16390, 'Й');
    req.write(chunk);
    req.write('a');
    req.end();

    // abort
    req.abort();

    // connection
    req.connection.on('pause', () => { });

    // event
    req.on('data', () => { });
}

{
    // Status codes
    let codeMessage: string = http.STATUS_CODES['400']!;
    codeMessage = http.STATUS_CODES[400]!;
开发者ID:SaschaNaz,项目名称:DefinitelyTyped,代码行数:31,代码来源:http.ts


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