如何在网址中发送百分比? [英] How to send percentage in url?

查看:67
本文介绍了如何在网址中发送百分比?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试发送这样的网址以获取搜索数据

I am trying to send a url like this for search data

http://localhost/project/search/text:75%

我在这里收到 400 - Bad Request 错误.

I am getting 400 - Bad Request error in here.

我什至尝试用 %25 替换百分比.但它没有奏效.我应该如何发送包含百分比的搜索数据?

I even tried replacing percentage with %25. But it didn't worked. How should I send the search data containing percentage?

推荐答案

在 URL 中,% 百分比字符保留用于字符编码.通常要表示 % 字符,您可以使用 %25,但是由于您已经尝试过此方法并且它对您不起作用,您应该改用 PHP的urlencode函数如下:

In URLs, the % percent character is reserved for character encoding. Usually to represent a % character you can use %25, but as you have already tried this and that it doesn't work for you, you should instead use PHP's urlencode function like so:

$url=urlencode("text:%75");

同样的问题发生在 : 上,因此这也防止了这个字符出现同样的问题(参考是 %3A).

The same issue occurs with :, this therefore prevents the same issue with this character also (which for reference is %3A).

部分来自 这个问题.

这篇关于如何在网址中发送百分比?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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