php file_get_contents 编码问题

发布于 2025-01-04 08:26:08 字数 368 浏览 2 评论 0原文

我正在尝试将短信服务集成到我的网站中。我需要使用名为“msg”(urlencoded)的参数进行 HTTP 调用。

目前,我正在使用经过 urlencode 的 msg 参数构建整个 URL(即 $msg = urlencode($msg)),并且正在发送短信。

$msg = urlencode("Hello World");

虽然我在手机上收到的是“Hello+World”而不是“Hello World”。

那么 file_get_contents 有问题吗?

另外,无论如何,我可以看到字符串“file_get_contents”最终发送出去吗?

I am trying to Integrate an SMS service into my website. I need to make a HTTP call with a param named "msg" (urlencoded).

Currently, I am constructing the entire URL with msg param being urlencoded (i.e $msg = urlencode($msg)), and I am sending the SMS.

$msg = urlencode("Hello World");

Although what I receive on my phone is "Hello+World" and NOT "Hello World".

So is there an issue with file_get_contents ?

Also, is there anyway, I can see the string "file_get_contents" finally sends out ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

爱你不解释 2025-01-11 08:26:09

尝试使用 rawurlencode() 代替。

主要区别(尽管还有其他区别)是它将空格编码为 %20 而不是 +。这很可能是您问题的根源。

Try using rawurlencode() instead.

The principal difference (although there are others) is that it encodes spaces as %20 instead of +. This is quite likely the source of your problem.

沐歌 2025-01-11 08:26:09

我想出了问题所在:

我使用 http_build_query 创建查询字符串,并且我向它传递了 urlencode 参数。因此它被编码了两次。

那么file_get_contents有问题吗?

不。

另外,有什么办法,我可以看到字符串 file_get_contents 最终发送出去吗?

是的,使用网络嗅探器。

I figured what was the issue:

I was using http_build_query to create the query string, and I was passing a urlencode'd param to it. Hence it was being encoded twice.

So is there an issue with file_get_contents ?

No.

Also, is there any way, I can see the string file_get_contents finally sends out ?

Yes, with a network sniffer.

许一世地老天荒 2025-01-11 08:26:09

检索数据后需要使用 urldecode() 然后显示给用户

You need to use urldecode() after retrieving data and then display to user

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文