Curl post gives weird characters like åäö

I have a controller in grails with post action. Now that with php and curl trying to send a message to the grails pipeline, I get ?placeholders for type characters åäö, etc. If I create a small html form that saves the same post, the grails controller gets parameters as åäö, not how ?, etc.

What is the difference between below and how can I get curl to act as an example of an html form?

Twisting example:

$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);

An example html form:

<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>
+3
source share
2 answers

"UTF-8" CURLOPT_ENCODING. identity, deflate gzip. Content-Type:

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

    curl_setopt($x, CURLOPT_POSTFIELDS, 'Foo=' . urlencode($value));
    
  • , $value utf-8, .. , , php utf-8.

0

All Articles