美文网首页
通过URL访问创建网络请求

通过URL访问创建网络请求

作者: YuWenHaiBo | 来源:发表于2016-05-11 13:21 被阅读60次

先看代码:

NSURLRequest *request = [NSURLRequest requestWithURL:url cachePolicy:(NSURLRequestCAchePolicy) timeoutInterval:(NSTiemInterval)  ]

这里第一个参数没啥好说的具体说说第二个参数 NSURLRequestCAchePolicy

  NSURLRequestUseProtocolCachePolicy = 0,
   NSURLRequestReloadIgnoringLocalCacheData = 1,
   NSURLRequestReloadIgnoringLocalAndRemoteCacheData = 4, // Unimplemented
   NSURLRequestReloadIgnoringCacheData =    NSURLRequestReloadIgnoringLocalCacheData,
    NSURLRequestReturnCacheDataElseLoad = 2,
    NSURLRequestReturnCacheDataDontLoad = 3,
    NSURLRequestReloadRevalidatingCacheData = 5, 

我们会看到5个枚举类型下面一一来解释下
首先看看xcode的英文解释

@discussion The NSURLRequestCachePolicy enum defines constants that
    can be used to specify the type of interactions that take place with
    the caching system when the URL loading system processes a request.
    Specifically, these constants cover interactions that have to do
    with whether already-existing cache data is returned to satisfy a
    URL load request.

中文翻译:

    @constant NSURLRequestUseProtocolCachePolicy Specifies that the
    caching logic defined in the protocol implementation, if any, is
    used for a particular URL load request. This is the default policy
    for URL load requests.

中文翻译:基础策略

 @constant NSURLRequestReloadIgnoringLocalCacheData Specifies that the
    data for the URL load should be loaded from the origin source. No
    existing local cache data, regardless of its freshness or validity,
    should be used to satisfy a URL load request.

中文翻译:忽略本地缓存

    @constant NSURLRequestReloadIgnoringLocalAndRemoteCacheData Specifies that
    not only should the local cache data be ignored, but that proxies and
    other intermediates should be instructed to disregard their caches
    so far as the protocol allows.  Unimplemented.

中文翻译:无视任何缓存策略,无论是本地的还是远程的,总是从原地址重新下载

  @constant NSURLRequestReloadIgnoringCacheData Older name for
    NSURLRequestReloadIgnoringLocalCacheData.

中文翻译:
NSURLRequestReloadIgnoringCacheData 是 NSURLRequestReloadIgnoringLocalCacheData 的旧名,这两个是一样的

    @constant NSURLRequestReturnCacheDataElseLoad Specifies that the
    existing cache data should be used to satisfy a URL load request,
    regardless of its age or expiration date. However, if there is no
    existing data in the cache corresponding to a URL load request,
    the URL is loaded from the origin source.

中文翻译:首先使用缓存,如果没有本地缓存,才从原地址下载

  @constant NSURLRequestReturnCacheDataDontLoad  Specifies that the
    existing cache data should be used to satisfy a URL load request,
    regardless of its age or expiration date. However, if there is no
    existing data in the cache corresponding to a URL load request, no
    attempt is made to load the URL from the origin source, and the
    load is considered to have failed. This constant specifies a
    behavior that is similar to an "offline" mode.

中文翻译:使用本地缓存,从不下载,如果本地没有缓存,则请求失败,此策略多用于离线操作

    @constant NSURLRequestReloadRevalidatingCacheData Specifies that
    the existing cache data may be used provided the origin source
    confirms its validity, otherwise the URL is loaded from the
    origin source.  Unimplemented.

中文翻译:如果本地缓存是有效的则不下载,其他任何情况都从原地址重新下载
</code>

第三个参数就是设置延迟时间,也就是你等他响应的时间。

相关文章

  • 通过URL访问创建网络请求

    先看代码: 这里第一个参数没啥好说的具体说说第二个参数 NSURLRequestCAchePolicy 我们会看到...

  • requests - get

    Get 方法 Requests 发送网络请求非常简单 直接get 访问URL地址 请求后返回response对象 ...

  • python网页爬虫,实现url可访问性统计

    1、程序功能设计 从txt文件中读取url,通过request对象进行访问,获取请求的响应状态,统计url访问异常...

  • [正儿八经PHP]抓取页面的几种方式

    我们在开发网络程序时,往往需要抓取非本地文件,一般情况下都是利用php模拟浏览器的访问,通过http请求访问url...

  • PHP抓取页面的几种方式

    我们在开发网络程序时,往往需要抓取非本地文件,一般情况下都是利用php模拟浏览器的访问,通过http请求访问url...

  • PHP抓取页面的几种方式

    我们在开发网络程序时,往往需要抓取非本地文件,一般情况下都是利用php模拟浏览器的访问,通过http请求访问url...

  • PHP抓取页面的几种方式

    我们在开发网络程序时,往往需要抓取非本地文件,一般情况下都是利用php模拟浏览器的访问,通过http请求访问url...

  • iOS开发中URL中不合法字符的转义

    通常我们在拼接网络请求Url的时候,比如请求网络图片,通过get方法请求网络数据,有时会遇到请求失败的问题,于...

  • HTTP协议了解

    HTTP方法 GET :请求访问的url资源,不安全,速度快,传输参数在url信息中 POST :请求访问url资...

  • NSURLSession 基本用法示例

    NSURLSession 基本用法示例 使用NSURLSession来执行网络请求: url获取访问服务器的路径 ...

网友评论

      本文标题:通过URL访问创建网络请求

      本文链接:https://www.haomeiwen.com/subject/kvcurttx.html