【发布时间】:2018-06-22 10:43:54
【问题描述】:
您好,我在 laravel 中已经有一个 api,但我需要使用 express node js 访问。
这是我的功能
var data = querystring.stringify({
_token: 'LhTsymoueRtcWtjP69MD1KEbDyGl0NGuewWOieER',
propertiesString: properties
});
var options = {
hostname: 'apiproperties.local',
port: 80,
path: '/properties/storeSB',
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'Content-Length': Buffer.byteLength(data)
}
/*headers: {
'Content-Type': 'application/json',
}*/
};
var req = http.request(options, function(res) {
res.setEncoding('utf8');
console.log('Status: ' + res.statusCode);
console.log('Headers: ' + JSON.stringify(res.headers));
res.on('data', function (chunk) {
console.log("body: " + chunk);
});
});
req.write(data);
req.end();
这给了我错误 Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php 第 68 行,因为我不发送 _token,但我不知道如何在 nodejs 中发送令牌我在 nodejs 中没有视图,因为我不想使用我不需要它,那么如何在我的发布请求中发送令牌而不在一个视图中调用表单?问候
【问题讨论】:
-
PHP 代码期望令牌在哪里?作为自定义标题?在查询字符串中?在 POST 正文中?
标签: node.js