防止从 URL 中删除等号的 URL 编码 [英] Prevent URL encoding that is removing equals signs from URL

查看:51
本文介绍了防止从 URL 中删除等号的 URL 编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在开发 Django/React 应用程序.我有一些验证电子邮件链接,如下所示:

https://test.example.com/auth/security_questions/f=ru&i=101083&k=7014c315f3056243534741610545c8067d64d747a981de22fe75b168a0d

在 dev env 中,这工作正常,但现在我已准备好投入生产,但无法正常工作.当我点击它时,它会将其转换为:

https://test.example.com/auth/security_questions/f%3Dru&i%3D101083&k%3D7014c315f3056243534741610545c8067d64d747a981de22a90d/code/b129025

这会阻止 react-router-dom 匹配正确的 URL,因此 Web 应用程序的一部分无法正确加载.

使用以下内容构建链接.

link = '%s/auth/security_questions/f=%s&i=%s&k=%s' % \('https://test.example.com', 'ru', user.id, user.key)

此外,这是捕获路由的url():

url(r'^(?:.*)/$', TemplateView.as_view(template_name='index.html')),

解决方案

这些变量应该是 queryGET 请求中的参数.当您构建链接时,您需要在其中将 URL 与查询字符串分开的地方有一个问号:

https://test.example.com/auth/security_questions/?f=ru&i=101083&k=7014c315...^|___这里

= 到 url 编码的 %3D 等的转换是正确的,等效的.有时变量直接是 URL 的一部分,但在这种情况下,Web 应用程序不使用 & 分隔的键/值对.

Working on a Django/React app. I have some verification emails links that look like the following:

https://test.example.com/auth/security_questions/f=ru&i=101083&k=7014c315f3056243534741610545c8067d64d747a981de22fe75b78a03d16c92

In dev env this works fine, but now that I am getting it ready for production, it isn't working. When I click on it, it converts it to:

https://test.example.com/auth/security_questions/f%3Dru&i%3D101083&k%3D7014c315f3056243534741610545c8067d64d747a981de22fe75b78a03d16c92/

This prevents react-router-dom from matching the correct URL, so a portion of the web application does not load properly.

The link is constructed using the following.

link = '%s/auth/security_questions/f=%s&i=%s&k=%s' % \
('https://test.example.com', 'ru', user.id, user.key)

Also, here is the url() that is catching the route:

url(r'^(?:.*)/$', TemplateView.as_view(template_name='index.html')),

解决方案

These variables are supposed to be query parameters in a GET request. When you construct the link, you'll need to have a question mark in there somewhere separating the URL from the query string:

https://test.example.com/auth/security_questions/?f=ru&i=101083&k=7014c315...
                                                 ^
                                                 |___ here

The conversion of = to url-encoded %3D etc is correct, and equivalent. Sometimes variables are part of the URL directly, but webapps don't use &-separated key/value pairs in that case.

这篇关于防止从 URL 中删除等号的 URL 编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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