我搜索了很多但仍未找到问题的原因:
在调用我的php webservice时,我将登录凭据("PeterPan:Ützel([])ÄÄÖÖ'")进行编码,并使用UTF-8传递:
$.ajaxSetup({
beforeSend: function(request) {
request.setRequestHeader("Authentication", auth);
},
type: "POST",
contentType: "charset=utf-8"
});
var tok = sUsername + ':' + sPassword;
var hash = this.Base64.encode(tok);
var auth = hash;
$.ajax({
url: "php/login.php"
});
在PHP中,我正在使用以下方法解码字符串:
$headers = array();
foreach($_SERVER as $key => $value) {
if (substr($key, 0, 5) <> 'HTTP_') {
continue;
}
$header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
$headers[$header] = $value;
}
$response['Encoded'] = base64_decode($headers['Authentication']);
$encoded = json_encode($response);
header("Content-Type: text/html; charset=utf-8");
echo $encoded;
当响应到达时,编码的字符串看起来像这样:"PeterPan:\u00dctzel([])\u00c4\u00c4\u00d6\u00d6'"
这些umlauts(附加符号)被错误地编码了...
我做错了什么?