zoukankan      html  css  js  c++  java
  • NSUrlConnection 和 NSUrlRequest 的关系

    开始看到这2个名字,总感觉NSUrlConnection才是主要的网络请求类,其实不是,先看官方文档

    An NSURLConnection object lets you load the contents of a URL by providing a URL request object. The interface for NSURLConnection is sparse, providing only the controls to start and cancel asynchronous loads of a URL request. You perform most of your configuration on the URL request object itself.
    
    Note: Although instances of this class are commonly called “connections”, there is not a 1:1 correlation between these objects and the underlying network connections.

    如上所说,这里的connection,并不是只真正的网络连接,它仅仅负责开始和取消网络请求,并且会负责分发网络回调方法。

    而NSURLRequest对象才是真正的网络设置类,一般利用NSMutableURLRequest类,它的主要方法如下:

    setURL:
    
    setHTTPMethod:
    
    setTimeoutInterval:
    
    - (void)addValue:(NSString *)value forHTTPHeaderField:(NSString *)field
    
    - (void)setHTTPBody:(NSData *)data

     

     

  • 相关阅读:
    C#概述
    作为一个程序员小小感悟!!
    c# 合并两个DataTable
    C# FastReport .NET打印
    c# System.Net.Sockets =》TcpListener用法
    开博第一章
    Vue 报错 Uncaught (in promise)
    ASP.NET MVC 中的过滤器
    SpringBoot 打包成war
    SprintBoot 实现上传下载
  • 原文地址:https://www.cnblogs.com/breezemist/p/3898664.html
Copyright © 2011-2022 走看看