我有一个 Ruby on Rails 应用程序,它是 Java 和 .Net 应用程序的服务器。我有一个自定义标头用于发送一些数据,但是当这些数据到达 Ruby on Rails 应用程序时,Rails 将值读取为 UTF-8,然后说该值不是有效的 UTF-8 字符串。
例如,如果我发送JÜRGENELITE-HP 我会得到:
#<ActiveRecord::StatementInvalid: PGError: ERROR: invalid byte sequence for encoding "UTF8": 0xdc52
: SELECT * FROM "replicas" WHERE ("replicas"."identification" = 'J?RGENELITE-HP') AND ("replicas".user_id = 121) LIMIT 1>
Java HTTP Client 库清楚地在控制台中正确打印数据:
DEBUG [main] (DefaultClientConnection.java:268) - >> POST /ze/api/files.json HTTP/1.1
DEBUG [main] (DefaultClientConnection.java:271) - >> X-Replica: JÜRGENELITE-HP
DEBUG [main] (DefaultClientConnection.java:271) - >> Authorization: Basic bWxpbmhhcmVzOjEyMzQ1Njc4
DEBUG [main] (DefaultClientConnection.java:271) - >> Content-Length: 0
DEBUG [main] (DefaultClientConnection.java:271) - >> Host: localhost:3000
DEBUG [main] (DefaultClientConnection.java:271) - >> Connection: Keep-Alive
DEBUG [main] (DefaultClientConnection.java:271) - >> User-Agent: Apache-HttpClient/4.1.2 (java 1.5)
但是当它到达 Rails 时它会中断。HTTP 使用什么编码来编码标头值?