我在 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
的有效值。您只能使用 identity
、deflate
或 gzip
。您需要在 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/