如何在express.js GET请求中访问正文? [英] How to access body in express.js GET request?

查看:64
本文介绍了如何在express.js GET请求中访问正文?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用内部使用express.js的sails.js框架中的GET请求中发送正文

I am sending body in GET request in sails.js framework which internally uses express.js

curl -u用户名:密码-i -H接受:应用程序/json" -X GET -d"msisdn = 32323"

curl -u username:password -i -H "Accept: application/json" -X GET -d "msisdn=32323" http://localhost:9000/api/v1.1/buy/voucher/raj/32323

我试图在express的req.body中获取msisdn的值,但它给了我未定义的信息.

i am trying to get the value of msisdn in req.body of express but it is giving me undefined.

我在互联网上阅读,上面说我们可以在GET请求中发送正文.您可以引用此stackoverflow线程.带有请求正文的HTTP GET

I read on internet and it says we can send body in GET request. You can refer this stackoverflow thread. HTTP GET with request body

推荐答案

使用Express无法发送带有GET请求的正文. http://expressjs.com/en/api.html#req.body

With Express it's not possible to send a body with a GET request. http://expressjs.com/en/api.html#req.body.

实际上,您甚至不需要此规范.如果要与GET请求一起发送数据,则查询参数就足够了,如果您需要安全地发送数据,则甚至根本不需要使用GET请求.

In reality, you shouldn't even want this Specification. If you want to send data with your GET request, query parameters will suffice, if you have the need to send data securely you shouldn't even want to use a GET request in the first place.

这篇关于如何在express.js GET请求中访问正文?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆