本文整理汇总了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();
}
示例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