博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
node 发出ajax请求_使用Node发出HTTP请求
阅读量:2513 次
发布时间:2019-05-11

本文共 1263 字,大约阅读时间需要 4 分钟。

node 发出ajax请求

I use the term HTTP, but HTTPS is what should be used everywhere, therefore these examples use HTTPS instead of HTTP.

我使用HTTP一词,但是HTTPS是应该在所有地方使用的术语,因此这些示例使用HTTPS代替HTTP。

执行GET请求 (Perform a GET Request)

const https = require('https')const options = {  hostname: 'flaviocopes.com',  port: 443,  path: '/todos',  method: 'GET'}const req = https.request(options, (res) => {  console.log(`statusCode: ${res.statusCode}`)  res.on('data', (d) => {    process.stdout.write(d)  })})req.on('error', (error) => {  console.error(error)})req.end()

执行POST请求 (Perform a POST Request)

const https = require('https')const data = JSON.stringify({  todo: 'Buy the milk'})const options = {  hostname: 'flaviocopes.com',  port: 443,  path: '/todos',  method: 'POST',  headers: {    'Content-Type': 'application/json',    'Content-Length': data.length  }}const req = https.request(options, (res) => {  console.log(`statusCode: ${res.statusCode}`)  res.on('data', (d) => {    process.stdout.write(d)  })})req.on('error', (error) => {  console.error(error)})req.write(data)req.end()

放入并删除 (PUT and DELETE)

PUT and DELETE requests use the same POST request format, and just change the options.method value.

PUT和DELETE请求使用相同的POST请求格式,只需更改options.method值即可。

翻译自:

node 发出ajax请求

转载地址:http://emqgb.baihongyu.com/

你可能感兴趣的文章
二值图像连通区域标记
查看>>
MVC in Javascript
查看>>
eclipse 创建的Android工程的结构
查看>>
第8章 Android异常与性能优化相关面试问题
查看>>
有道单词导入 大量有道单词 生词本 批量导入 添加 有道单词XML 背单词
查看>>
jQuery Easing动画效果扩展插件
查看>>
bzoj 1002 [FJOI2007]轮状病毒 Matrix-Tree定理+递推
查看>>
Selenium WebDriver- 操作JavaScript的Alert弹窗
查看>>
娘的,自己的求逆序对模板又不好使了。。。。。。。。
查看>>
C#面向对象模式设计第十四讲:Template Method 模板模式(行为型模式)
查看>>
linux后台运行命令:&和nohup
查看>>
springboot + shiro学习(配置SecurityManager,Realm)
查看>>
http://desk.zol.com.cn/1600x900/
查看>>
Linux基础之命令练习Day3-文件管理:cat,tar,gzip,vim,ln
查看>>
iOS中使用nil NULL NSNULL的区别
查看>>
Hdu1754-线段树-单点更新
查看>>
在python中使用正则表达式(一)
查看>>
asp.net mvc 4.0的部署
查看>>
WordPress资源站点推荐
查看>>
Python性能鸡汤
查看>>