Wordpress提供了一个名为"the_permalink()"的函数,它返回,你猜对了!,在一个帖子循环中,给定帖子的永久链接.
我正在尝试URL编码永久链接,当我执行此代码时:
<?php
print(the_permalink());
$permalink = the_permalink();
print($permalink);
print(urlencode(the_permalink()));
print(urlencode($permalink));
$url = 'http://wpmu.local/graphjam/2008/11/06/test4/';
print($url);
print(urlencode($url));
?>
Run Code Online (Sandbox Code Playgroud)
它以HTML格式生成这些结果:
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http://wpmu.local/graphjam/2008/11/06/test4/
http%3A%2F%2Fwpmu.local%2Fgraphjam%2F2008%2F11%2F06%2Ftest4%2F
Run Code Online (Sandbox Code Playgroud)
我希望输出的第2,3和5行是URL编码的,但只有第5行是这样的.思考?
如果您查看此处的此表,您会发现它有一个 Unicode 字符的转义序列列表,但实际上对我来说不起作用。
\n\n例如,对于“%96”,它应该是 \xe2\x80\x93,我在尝试解码时收到错误:
\n\ndecodeURIComponent("%96");\nURIError: URI malformed\nRun Code Online (Sandbox Code Playgroud)\n\n如果我尝试编码“\xe2\x80\x93”,我实际上得到:
\n\nencodeURIComponent("\xe2\x80\x93");\n"%E2%80%93"\nRun Code Online (Sandbox Code Playgroud)\n\n我在互联网上搜索,看到了这个页面,其中提到分别使用 escape 和 unescape 与decodeURIComponent和encodeURIComponent。这似乎没有帮助,因为无论我尝试什么,%96 都不会显示为“\xe2\x80\x93”,这当然是行不通的:
\n\ndecodeURIComponent(escape("%96));\n"%96"\nRun Code Online (Sandbox Code Playgroud)\n\n不是很有帮助。
\n\n如何使用 JavaScript 将“%96”变为“\xe2\x80\x93”(无需为我可能遇到的每个可能的 unicode 字符硬编码映射)?
\n我的服务器上有一个名为:
some image.png
Run Code Online (Sandbox Code Playgroud)
名字里有一个空格。当我在浏览器(chrome)中输入 url 时,它会将空格转换为 %20:
some%20.png
Run Code Online (Sandbox Code Playgroud)
当我从应用程序中使用 URLEncoder.encode("some image.png") 时,我得到:
some+image.png
Run Code Online (Sandbox Code Playgroud)
这会导致 404。正确的编码方式是什么?
我正在开发一个功能,用户的电子邮件客户端只需打开预先填写的内容(javascript).
问题是我在转换特殊字符时遇到问题,因此它们被正确显示在电子邮件客户端中(由url传递的内容).
我写了一个函数,但在做了一个后console.log()我发现它甚至不会转换字符(可能是因为我试图char用a 代替string).
function url_encode(item)
{
for (i in item)
{
a = item[i]
switch (a)
{
case "À": a='%C0';
break;
case "È": a='%C8';
break;
case "É": a='%C9';
break;
case "Ê": a='%CA';
break;
case "à": a='%E0';
break;
case "è": a='%E8';
break;
case "é": a='%E9';
break;
case "ê": a='%EA';
break;
case "ë": a='%EB';
break;
}
item[i] = a;
console.log(item[i])
}
return item;
}
Run Code Online (Sandbox Code Playgroud)
任何人都找到了成功的方法或有想法(或修复)为什么这不能按预期工作?
编辑:encodeURI函数不支持é和è字符(在法语中使用很多),结果为é和è …
我需要使用用户名和/或密码中的特殊字符通过url使用j_spring_security_check登录
http://localhost:8080/appname/j_spring_security_check?j_username=username&j_password=üüü
Run Code Online (Sandbox Code Playgroud)
不起作用
http://localhost:8080/appname/j_spring_security_check?j_username=username&j_password=%c3%bc%c3%bc%c3%bc
Run Code Online (Sandbox Code Playgroud)
("üüü"urlencoded)也不起作用
有什么建议吗?如果您需要查看任何其他配置,请告诉我们.
谢谢
我正在尝试使用此函数使url编码为长字符串
NSData *PostData = [MyString dataUsingEncoding:NSUTF8StringEncoding];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:@"http://xxxxxxx.com/save.php"]];
[request setValue:@"gzip" forHTTPHeaderField:@"Accept-Encoding"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:PostData];
[request setHTTPMethod:@"POST"];
Run Code Online (Sandbox Code Playgroud)
但是我把它保存到我的sql时会遗漏一些数据,例如我们有这个包含特殊字符的字符串
("Text!@#&( |'l;,.")和<smile faces
当这个字符串收到我的服务器后,我错过了这个&之后的字符串和笑脸?
我需要将西里尔字符串转换为Windows-1251编码的urlencoded版本.对于以下示例字符串:
Моцарт
正确的结果应该是:
%CC%EE%F6%E0%F0%F2
在PHP中,我只需执行以下操作:
$request = urlencode(iconv("UTF-8", "windows-1251", "??????"));
echo $request;
Run Code Online (Sandbox Code Playgroud)
如何在Python中实现相同的目标?
我目前正在尝试对字符串进行编码以插入到 URL 中。我的问题是,当我的字符串包含反斜杠时,这似乎会失败。到目前为止,我已经使用 URLencode、curlEscape(来自 RCurl)和curlPercentEncode(来自 RCurl)函数尝试了 4 种方法,但没有一个成功。
> URLencode("hello\hello")
Error: '\h' is an unrecognized escape in character string starting ""hello\h"
> curlEscape("hello\hello")
Error: '\h' is an unrecognized escape in character string starting ""hello\h"
> curlPercentEncode("hello\hello")
Error: '\h' is an unrecognized escape in character string starting ""hello\h"
> curlPercentEncode("hello\hello", amp=TRUE)
Error: '\h' is an unrecognized escape in character string starting ""hello\h"
Run Code Online (Sandbox Code Playgroud) 如果我有一个随机字符串并想将其编码为另一个仅包含字母数字字符的字符串,那么在 JavaScript / NodeJS 中最有效的方法是什么?
显然,必须可以在需要时将输出字符串转换回原始输入字符串。
谢谢!
我有一个在Tomcat上运行的Spring-Boot应用程序。在其中,我有一个带有请求参数的RestController。不读取或作为查询参数传递。例如,如果我给出,则控制器方法不会作为值@RequestParam'&''#'http://localhost:8080/v1/test?query=&&
@RequestMapping(value = "/v1/test", method = RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)
public String getV2LocationByName(
@RequestParam
String cityName cityName,
@RequestParam(value = LANGUAGE, defaultValue = US_ENGLISH_LOCALE) String language,
HttpServletRequest request) throws InterruptedException, ExecutionException {
--------------
---------------
System.out.println(cityName);
}
Run Code Online (Sandbox Code Playgroud)
上面的程序为 & 和 # 返回空输出
为什么 spring 限制这些特殊字符,但不限制任何其他特殊字符?并且如果使用查询参数为 'Andaman&Nicobar',则查询参数被读取为 'Andaman'
urlencode ×10
javascript ×3
java ×2
spring ×2
string ×2
utf-8 ×2
encode ×1
encoding ×1
function ×1
node.js ×1
objective-c ×1
php ×1
python ×1
r ×1
rcurl ×1
security ×1
spring-boot ×1
spring-mvc ×1
unicode ×1
wordpress ×1