2017-06-02 94 views
0

例如在堆栈溢出的链接到我的个人资料在这里看起来是这样的:如何使用请求模块以unicode字符获取URL?

https://stackoverflow.com/users/607407/tomáš-zato 

但是,如果我从浏览器栏复制它,实际值是:

https://stackoverflow.com/users/607407/tom%C3%A1%C5%A1-zato 

您可以粘贴任这些在你的浏览器,它会工作。但是,如果我发送非URL编码使用Unicode(到不同的网页),我得到一个错误:

<html><body><h1>400 Bad request</h1> 
Your browser sent an invalid request. 
</body></html> 

如何Unicode字符转换成URL他们%XX变种?

回答

0

然后encodeurl模块帮助我:

const encodeUrl = require('encodeurl') 

用法:

options.url = encodeUrl(options.url);