如何发送名称中带有“ _”的HTTP标头字段?

时间:2019-05-17 00:16:49

标签: swift http

我有一组随任务发送的标题键。当我在服务器端查看所有包含_的标头时,就会出现问题。如何在标头值中插入_?使用Unicode值?使用UTF-8?如果是这样,在哪里?

request.setValue("4435353", forHTTPHeaderField: "session_id")
request.setValue("08", forHTTPHeaderField: "channel-id")
request.setValue("5afde734-7655-406d-bda3-14ffa968d6ab", forHTTPHeaderField: "itau-client-id")
request.setValue("oO6oO3nW6iG8yV0kL6gU5yY1hE3qV6bH6yF0mK0tG4xX3qU2gD", forHTTPHeaderField: "itau-client-secret")
request.setValue("\(token_latam!)", forHTTPHeaderField: "token_latam")
request.setValue("itoken", forHTTPHeaderField: "application")
request.setValue("2017-12-12T12:30:00", forHTTPHeaderField: "timestamp")
request.setValue("c626ea51-edde-4172-8d16-1c2fd7700c13", forHTTPHeaderField: "itau-chave")
request.setValue("345353454", forHTTPHeaderField: "transaction_id")
request.setValue("\(encoded_operation!)", forHTTPHeaderField: "encoded_operation")
request.setValue("application/json", forHTTPHeaderField: "Content-Type")

服务器端:

{
  "itau-chave": "c626ea51-edde-4172-8d16-1c2fd7700c13",
  "accept": "*/*",
  "timestamp": "2017-12-12T12:30:00",
  "itau-client-secret": "oO6oO3nW6iG8yV0kL6gU5yY1hE3qV6bH6yF0mK0tG4xX3qU2gD",
  "itau-client-id": "5afde734-7655-406d-bda3-14ffa968d6ab",
  "channel-id": "08",
  "application": "itoken",
  "accept-language": "en-us",
  "accept-encoding": "br, gzip, deflate",
  "user-agent": "ItauPassEmpresa/1 CFNetwork/975.0.3 Darwin/18.5.0",
  "content-type": "application/json"
} 

1 个答案:

答案 0 :(得分:0)

只需尝试在前缀标头名称中添加:以获得更多信息,请阅读此HTTP::Headers