码迷,mamicode.com
首页 > 移动开发 > 详细

ios网络:应用一个请求的7个步骤

时间:2015-09-04 22:29:05      阅读:197      评论:0      收藏:0      [点我收藏+]

标签:

Splitting big tasks into small tasks is often one of the best ways to solve a problem. Thus, in the next few exercises, we will split each request/method into a 7 step process. In the source code, I have commented each of these steps to assist you as you implement the requests.

7 Step Process

  1. Set the parameters
  2. Build the URL
    • Combine the base URL, the method being used, and the parameters to create the final URL for the request
  3. Configure the request
    • Create a NSURLRequest or NSMutableURLRequest using the URL
    • (If necessary) When using a NSMutableURLRequest, you may need to configure the request‘s header fields and HTTP body
  4. Make the request
    • Using the shared NSURLSession singleton, issue the request and specify a completion handler
  5. Parse the data
    • Assuming there is no error when the request returns, parse the response data into a usable type like a NSDictionaryNSArray, or [String:AnyObject], ...
  6. Use the data!
    • Extract the data required for the specified task
  7. Start the request
    • To initiate the request, it must be started (resumed)

ios网络:应用一个请求的7个步骤

标签:

原文地址:http://www.cnblogs.com/dagon/p/4782415.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!