自定义http头值 - 尝试传递变音符字符 [英] custom http header value - trying to pass umlaut characters

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

问题描述

使用nodejs,expressjs 3.x。



作为我们在用户名中传递的授权标头之一。
我们的一些用户名包含umlaut字符:üöä等。
对于只有正常字符的用户名都可以正常工作。
,但是当jörg尝试发出请求时,服务器无法识别标题中的变音符号。



尝试模拟问题I: / p>


  • 创建了一些用umlaut字符设置用户名头的测试。

    这些测试通过,他们能够通过在umlaut正确。

  • 使用了postman和高级休闲客户端Chrome扩展程序,并针对服务器手动进行了请求 - 在这种情况下,它失败。我看到服务器无法识别umlaut字符,它突然解释为某种类型。



自定义http头值的字符禁止使用这些类型的字符?
任何想法为什么它将在测试中工作,但不是从我的浏览器扩展?
我忘了在某处设置一些字符集吗?



任何帮助将是伟大的!

解决方案

在其他相关问题和评论中撰写的摘要:




  • 您可以将任何可列印的ascii字符您的自定义标题值字段

  • 如果要使用特殊字符,请按照您选择的规则/字符集/编码进行编码。只要这个编码使用简单的ascii chars它的确定。一个例子是在服务器端使用UTF-8和编码字符串字符到\u %%。

  • 你必须手工编码编码的字符串,您选择的字符集/编码范例的规则。


Using nodejs, expressjs 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 char-set somewhere?

any help would be great!

解决方案

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 chars following whatever rules/charset/encoding you choose. as long as this encoding it uses simple ascii chars its 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 charset/encoding paradigm you chose before.

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

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