如何将带有哈希的 url 发送到 nodejs [英] How to send url with hash to nodejs

查看:38
本文介绍了如何将带有哈希的 url 发送到 nodejs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将带有哈希的 URL 发送到 nodejs?

How do I send URL with hash to nodejs?

当我尝试发送带有哈希值的 URL 时,它不起作用,但使用 ? 时它起作用.

When I try to send a URL with hash in it, it doesn't work, but with ? it works.

const url = require('url');
const qs = require('querystring');
const http = require('http');
    
http.createServer(server).listen(1337, 'hostname');

function server(req, res) {
    res.writeHead(200, {'Content-Type': 'text/plain'});
    res.write(req.url);
    
    var currentURL = url.parse(req.url, true);
    console.log(currentURL);
    res.end('\nHello World\n');
}
    
console.log('Server running at http://127.0.0.1:1337/');

用例:Facebook access_token URL 格式类似于上面的内容

Use case: Facebook access_token URL format is something similar to above

推荐答案

'#' 标记后的 URL 部分,称为 fragment,不发送到服务器.如果您将数据存储在片段中,则由您来处理该数据并使用 GET 参数中的数据执行 ajax 请求.

The part of the URL after the '#' mark, called the fragment, is not sent to the server. If you store data in the fragment, then it is up to you to process that data and do an ajax request with the data in a GET argument.

这篇关于如何将带有哈希的 url 发送到 nodejs的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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