當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript ClientRequest.write方法代碼示例

本文整理匯總了TypeScript中http.ClientRequest.write方法的典型用法代碼示例。如果您正苦於以下問題:TypeScript ClientRequest.write方法的具體用法?TypeScript ClientRequest.write怎麽用?TypeScript ClientRequest.write使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在http.ClientRequest的用法示例。


在下文中一共展示了ClientRequest.write方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: 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

示例2:

// http ClientRequest
{
    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
開發者ID:SaschaNaz,項目名稱:DefinitelyTyped,代碼行數:31,代碼來源:http.ts


注:本文中的http.ClientRequest.write方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。