使用 PHP 转义 CURL @ 符号 [英] Escaping CURL @ symbol with PHP
问题描述
我正在编写一个 php 应用程序,该应用程序通过 curl 数据提交以注册 iContact 电子邮件列表.但是我不断收到无效的电子邮件地址错误.我认为这可能是因为我正在转义 @ 符号,因此它看起来像 %40 而不是 @.另外,根据带有 CURLOPT_POSTFIELDS 的 curl_setopt 的 php 文档:
I'm writing a php application that submits via curl data to sign up for an iContact email list. However I keep getting an invalid email address error. I think this may be due to the fact that I'm escaping the @ symbol so it looks like %40 instead of @. Also, according to the php documentation for curl_setopt with CURLOPT_POSTFIELDS:
要在 HTTP 中发布的完整数据POST"操作.要发布文件,在文件名前面加上@ 并使用完整路径.
The full data to post in a HTTP "POST" operation. To post a file, prepend a filename with @ and use the full path.
那么,无论如何,是否可以通过 php 中的 curl 将 @ 符号作为发布数据传递,而无需先通过 urlencode 运行它?
So, is there anyway to pass the @ symbol as post data through curl in php without running it through urlencode first?
推荐答案
使用 http_build_query()
在将它传递给 curl_setopt()
之前首先在你的数据数组上,这将导致它以 application/x-www-form-encoded
的形式发送表单multipart/form-data
(因此@ 不被解释).
Use http_build_query()
on your data-array first before passing it to curl_setopt()
, that will lead to it sending the form as application/x-www-form-encoded
instead of multipart/form-data
(and thus the @ is not interpreted).
另外,你为什么真正关心电子邮件地址中的@?仅当 @ 是第一个字符时才重要,而不是中间的某个位置.
Also why do you really care about the @ in an email-address? It only matters if the @ is the first character, not somewhere in the middle.
这篇关于使用 PHP 转义 CURL @ 符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!