php - curl 帖子给出奇怪的字符,如 åäö

标签 php grails encoding curl

我在 grails 中有一个带有后期操作的 Controller 。 现在,当通过 php 和 curl 尝试发布到 grails contoller 时,我得到 ? 占位符,用于 åäö 等字符。 如果我在同一篇文章中创建一个小的 html 表单,grails contoller 接收参数作为 åäö 而不是 ? 等。

下面有什么区别,我怎样才能让 curl 充当 html 表单示例?

curl 示例:

$x = curl_init("http://localhost/post");      
curl_setopt($x, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded'));  
curl_setopt($x, CURLOPT_POST, 1);  
curl_setopt($x, CURLOPT_POSTFIELDS, "Foo=ö");  
curl_setopt( $x, CURLOPT_ENCODING, "UTF-8" );   
curl_setopt($x, CURLOPT_RETURNTRANSFER, 1);  
$data = curl_exec($x);   
curl_close($x);

html 表单示例:

<html> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head><title></title></head>
<body>
<form name="input" action="http://localhost/post" method="post" enctype="application/x-www-form-urlencoded">
<TEXTAREA NAME="Foo" COLS=10 ROWS=4 type=text>ö</TEXTAREA>
<input class="button" type="submit" value="send"/>
</form>
</body>
</html>

最佳答案

“UTF-8” 不是 CURLOPT_ENCODING 的有效值。您只能使用 identitydeflategzip。您需要在 Content-Type header 中进行设置:

curl_setopt($x, CURLOPT_HTTPHEADER, array('Content-Type: application/x-www-form-urlencoded; charset=UTF-8'));  

关于php - curl 帖子给出奇怪的字符,如 åäö,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5920308/

相关文章:

python - 当cursor.fetchall()时出现UnicodeDecodeError

PHP DateTime->sub() 不会冒泡长达几天

php - Browscap.ini 丢失

Grails 和导航插件 : Rendering SubItems from different controllers?

Grails 日志记录 - 是否有任何现有的解决方案能够记录实际发生调用的文件 + 行?

java - 如何指定我想要的 UTF-8 版本(在 Java 中)?

php - Symfony:学说进程 d:s:u 但数据库没有变化

php - 使用 php 爬虫索引数据到 ElasticSearch

Grails Spring安全核心,如何手动设置主体

encoding - 猜测UTF-8编码