HTTP 参数和 HTTP 标头有什么区别?

What is the difference between HTTP parameters and HTTP headers?(HTTP 参数和 HTTP 标头有什么区别?)

本文介绍了HTTP 参数和 HTTP 标头有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我阅读了 this 问题,但它没有回答我的问题.

I read this question but it didn't answer my question.

对我来说,标题和参数都是字典,不同之处在于标题是 [String : String] 而参数是 [String : AnyObject]? 等等,如果你的参数也是字符串,那么您可以在标题中发送它们(同时使用x-"前缀表示它们不是标准标题),这是一种常见但不是好的做法.

To me Headers and Parameters are both dictionaries with the difference that headers is [String : String] while Parameters is [String : AnyObject]? and so if your parameters are also Strings then you could send them within the headers (while using a 'x-' prefix to signify they aren't standard headers) which is a common but not good practice.

  • 正确吗?
  • headersparameters 还有其他区别吗?
  • 您会使用 parameters 发送哪些其他非字符串类型?
  • Is that correct?
  • Are there other difference between headers and parameters?
  • What kind of other non-String types would you be sending using parameters?

Alamofire 请求方法

Alamofire Request method

public func request(
        method: Method,
        _ URLString: URLStringConvertible,
          parameters: [String: AnyObject]? = nil,
          encoding: ParameterEncoding = .URL,
          headers: [String: String]? = nil)
        -> Request
    {
        return Manager.sharedInstance.request(
            method,
            URLString,
            parameters: parameters,
            encoding: encoding,
            headers: headers
        )
    }

作为一个例子,我看到人们通过 ["x-ios-version" : UIDevice.currentDevice().systemVersion] 或通过标题构建版本

As an example I have seen people passing ["x-ios-version" : UIDevice.currentDevice().systemVersion] or build versions through headers

推荐答案

以下是差异列表:

  1. 它们是为不同的目的而设计的.标头携带元信息,参数携带实际数据.

  1. They are designed for different purposes. Headers carry meta info, parameters carry actual data.

HTTP 服务器将自动取消转义/解码参数名称/值.这不适用于标头名称/值.

HTTP Server will automatically un-escape/decode parameter names/values. This does not apply to header names/values.

标题名称/值需要在客户端手动转义/编码,并在服务器端手动取消转义/解码.经常使用 Base64 编码或百分比转义.

Header names/values need to be manually escaped/encoded at client side and be manually un-escaped/decoded at server side. Base64 encoding or percent escape is often used.

最终用户可以看到参数(在 URL 中),但标题对最终用户是隐藏的.

Parameters can be seen by end-users (in URL), but headers are hidden to end-users.

这篇关于HTTP 参数和 HTTP 标头有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:HTTP 参数和 HTTP 标头有什么区别?

基础教程推荐