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

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

问题描述

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

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 Request方法

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.

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

Server side will automatically un-escape/decode parameter names/values. This does not apply for 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 (query parameters) on URL but headers are hidden to end-users.

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

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