[英]NodeJS - how to send body in POST request?
I need to use http
internal NodeJS library to make a POST
request, how can i attach body
object with this request?我需要使用
http
内部 NodeJS 库来发出POST
请求,如何将body
object 附加到此请求中? When I'm looking into http.RequestOptions
I don't see any data
or body
property:/当我查看
http.RequestOptions
时,我没有看到任何data
或body
属性:/
import * as http from "http";
const options2: http.RequestOptions = {
hostname: 'www.google.com',
port: 80,
path: '/upload',
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Content-Length': Buffer.byteLength(null)
},
};
http.request(options, (res: http.IncomingMessage) => {
});
thanks for any help!谢谢你的帮助!
http.request
returns an http.ClientRequest
object .http.request
返回http.ClientRequest
object 。
You need to call the write
method on that and pass in your body data.您需要对其调用
write
方法并传入您的正文数据。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.