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

2023-07-08移动开发问题
2

本文介绍了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 标头有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

无法将文件从捆绑包复制到 iOS 中的文档目录
Can`t copy file from bundle to documents directory in iOS(无法将文件从捆绑包复制到 iOS 中的文档目录)...
2024-04-15 移动开发问题
4

如何复制“字典"在斯威夫特?
How to copy a quot;Dictionaryquot; in Swift?(如何复制“字典在斯威夫特?)...
2024-04-15 移动开发问题
10

Swift - 迭代结构对象时如何对其进行变异
Swift - How to mutate a struct object when iterating over it(Swift - 迭代结构对象时如何对其进行变异)...
2024-04-15 移动开发问题
7

如何使用 Swift 将文本复制到剪贴板/粘贴板
How to copy text to clipboard/pasteboard with Swift(如何使用 Swift 将文本复制到剪贴板/粘贴板)...
2024-04-15 移动开发问题
9

Swift 无法使用类型为“([Score],Score)"的参数列表调用“find",其中 Sco
Swift Cannot invoke #39;find#39; with an argument list of type #39;([Score], Score)#39; where Score is a struct(Swift 无法使用类型为“([Score],Score)的参数列表调用“find,其中 Score 是一个结构)...
2024-04-15 移动开发问题
6

如何使用 UIImageViewExtension 与 Swift 异步加载图像并防止重复图像或错误图像加载到单元格
How to load image asynchronously with Swift using UIImageViewExtension and preventing duplicate images or wrong Images loaded to cells(如何使用 UIImageViewExtension 与 Swift 异步加载图像并防止重复图像或错误图像加载到单元格) - IT屋-程序员软...
2024-04-15 移动开发问题
3