自定义HTTP标头值 - 尝试传递变音符号 [英] Custom HTTP header value - trying to pass umlaut characters

查看:215
本文介绍了自定义HTTP标头值 - 尝试传递变音符号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Node.js和Express.js 3.x。



作为我们的授权头之一,我们传递用户名。我们的一些用户名包含umlaut字符:üöä和喜欢的。
对于只有正常字符的用户名,一切正常。但是当jörg尝试提出请求时,服务器无法识别头文件中的变音符号。



试图模拟问题I:




  • 创建了一些使用变音符字符设置用户名标题的测试。这些测试通过,他们可以正确地传入变音器。

  • 使用'postman'和'高级休息客户端'Chrome扩展,并且手动对服务器进行请求 - 在这种情况下失败。我看到服务器无法识别变音符号,它会将其解释为某种



自定义HTTP头值是否有限制禁止使用这些字符的字符?任何想法为什么它可以在测试中工作,但不是从我的浏览器扩展?我忘记在某个地方设置一些字符集?

解决方案

在其他相关问题和意见中写的内容摘要: / p>


  • 您可以将任何可打印ASCII字符

  • 如果要使用特殊字符,请按照您选择的任何规则/字符集/编码进行编码。只要这个编码使用简单的ASCII字符就可以了。一个例子是使用UTF-8并将字符串字符编码为\u %%。

  • 在服务器端 - 您必须手动对已编码的字符串感兴趣,可能通过使用


I am using Node.js and Express.js 3.x.

As one of our authorization headers we are passing in the username. Some of our usernames contain umlaut characters: ü ö ä and the likes of. For usernames with just 'normal' characters, all works fine. But when a jörg tries to make a request, the server doesn't recognize the umlaut character in the header.

Trying to simulate the problem I:

  • Created some tests that set the username header with the umlaut character. These tests pass, they are able to pass in the umlaut correctly.
  • Used 'postman' and 'advanced rest client' Chrome extensions and made the request manually against the server - in this case it failed. I saw the server is unable to recognize the umlaut character, it juts interpreted it as some sort of ?.

Is there any limitation on custom HTTP header values characters that forbids using these kind of characters? Any idea why it would work in tests but not from my browser extension? Am I forgetting to set some character set somewhere?

解决方案

Summary of what was written in the other related question and in comments:

  • You may put any 'printable' ASCII char in your custom header value field.
  • If you want to use special characters, encode these characters following whatever rules/charset/encoding you choose. As long as this encoding it uses simple ASCII chars, it's OK. An example is using UTF-8 and encoding string chars to \u%%.
  • On the server side - you must manually make sense out of the encoded string, probably by decoding it using the rules of the character set/encoding paradigm you chose before.

这篇关于自定义HTTP标头值 - 尝试传递变音符号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆