【Swift】 GET&POST请求 网络缓存的简单处理

本文介绍了Swift中GET和POST请求的区别,包括参数位置、效率和缓存特性。同时,讨论了GET请求的缓存问题,并提供了关于iOS中NSURLCache存储目录的简述,以及如何清理缓存数据。
摘要由CSDN通过智能技术生成

%26nbsp;GET %26amp; POST 的对比

%26nbsp;

源码:https://github.com/SpongeBob-GitHub/Get-Post.git

%26nbsp;

%26nbsp;1. URL

%26nbsp; %26nbsp; - GET

%26nbsp; %26nbsp; %26nbsp; %26nbsp; 所有的参数都包含在 URL 中

%26nbsp;

%26nbsp; %26nbsp; %26nbsp; %26nbsp; 1. 如果需要添加参数,脚本后面使用 `?`

%26nbsp; %26nbsp; %26nbsp; %26nbsp; 2. 参数格式:值对

%26nbsp; %26nbsp; %26nbsp; %26nbsp; %26nbsp; %26nbsp; 参数名=值

%26nbsp; %26nbsp; %26nbsp; %26nbsp; 3. 如果有多个参数,使用 `%26amp;` 连接

%26nbsp; %26nbsp; %26nbsp; %26nbsp; 4. 在 get 方法中,url字符串中不能包含中文或者特殊符号 空格

%26nbsp;%26nbsp; %26nbsp; %26nbsp; %26nbsp; %26nbsp; 如果出现,需要添加百分号转义

%26nbsp;

%26nbsp; %26nbsp; - POST

%26nbsp; %26nbsp; %26nbsp; %26nbsp; URL中不包含参数,直接指定登录脚本即可

%26nbsp;

%26nbsp;2. Request

%26nbsp;

%26nbsp; %26nbsp; - GET

%26nbsp; %26nbsp; %26nbsp; %26nbsp; - 因为 GET 的效率高,而且性能好,能够被缓存,使用频率高

%26nbsp; %26nbsp; %26nbsp; %26nbsp; - 是默认的请求方法,不需要任何设定

%26nbsp;

%26nbsp; %26nbsp; - POST

%26nbsp; %26nbsp; %26nbsp; %26nbsp; - 需要指定请求方法

%26nbsp; %26nbsp; %26nbsp; %26nbsp; %26nbsp; %26nbsp; request.HTTPMethod = @"POST";

%26nbsp; %26nbsp; %26nbsp; %26nbsp; - 所有参数都包含在请求体中,二进制数据,来源:firebug的源代码中粘贴

%26nbsp; %26nbsp; %26nbsp; %26nbsp; - 参数格式,和 GET 的几乎一致,只是没有 `?`

%26nbsp; %26nbsp; %26nbsp; %26nbsp; - POST方法获得的网络数据不能被缓存

%26nbsp;

%26nbsp;3. Connection

%26nbsp; %26nbsp; 这是一个最单纯的网络方法,只是发送"

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值