首页 > 移动平台 > 详细

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

时间:2015-09-04 22:29:01      阅读:356      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!