dppfxf909679
2017-08-02 21:25
浏览 115
已采纳

PHP POST请求特殊字符

I'm trying to send a special character, such as ñ, through a POST request in PHP. When I do it, it comes out as ñ, what is wrong and how do I fix it?

I'm sending and receiving the post request in PHP, here is what I use to send it:

$url = '<url>';
$data = array('key' => 'ñ');

$options = array(
    'http' => array(
        'header'  => "Content-type: application/x-www-form-urlencoded
",
        'method'  => 'POST',
        'content' => http_build_query($data)
    )
);
$context  = stream_context_create($options);
$result = file_get_contents($url, false, $context);

echo $result;

Thanks in advance!

图片转代码服务由CSDN问答提供 功能建议

我正在尝试通过POST发送一个特殊字符,例如ñ 请求PHP。 当我这样做时,它出现为ñ,有什么问题,如何解决?

我正在发送和接收邮件请求 PHP,这是我用来发送它的:

  $ url ='&lt; url&gt;'; 
 $ data = array('key'=&gt;'ñ  '); 
 
 $ options = array(
'http'=&gt; array(
'header'=&gt;“Content-type:application / x-www-form-urlencoded 
 
”,  
'method'=&gt;'POST',
'content'=&gt; http_build_query($ data)
)
); 
 $ context = stream_context_create($ options); 
 $ result = file_get_contents(  $ url,false,$ context); 
 
echo $ result; 
   
 
 

提前致谢!

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douyong1850 2017-08-02 21:43
    已采纳

    Try using this:

    $data = array('key' => urlencode('ñ'));
    

    And in the $url file:

    $_POST['key']=urldecode($_POST['key']);
    

    This is how I use to send special characters in GET and POST method with ajax, it must work for php too.

    点赞 打赏 评论

相关推荐 更多相似问题