ASIHTTPRequest vs AFNetworking vs NSUrlRequest

前端 未结 4 572
名媛妹妹
名媛妹妹 2021-02-01 03:29

In the past I have use ASIHTTPRequest but now there is NSURLRequest. Should we be using the NSURLRequest now? Are there any disadvantages

相关标签:
4条回答
  • 2021-02-01 04:09

    NSURLConnection and NSURLRequest are the provided Cocoa classes for managing connections. In iOS 7, Apple added NSURLSession.

    But I think you'll find AFNetworking to be a framework that further simplifies network requests (notably complex HTTP requests). If you don't want to use third-party frameworks for any reason, you can use NSURLConnection and/or NSURLSession directly. It just takes a little more coding.

    If you're looking for a good ASIHTTPRequest alternative, AFNetworking is a great candidate.

    For information on NSURLConnection and NSURLSession see the URL Loading System Programming Guide.

    0 讨论(0)
  • 2021-02-01 04:13

    NSURLRequest has been there since iOS2.0 (see the doc), so it is not precisely new. ASIHTTPRequest has been discontinued, the last update was on 15th May 2011, so you shouldn't use it. AFNetworking is a delightful networking library for iOS and Mac OS X as described by them self, and really makes your live easier, in my case it is the first framework I include in my network required projects.

    Which one you should use?, I think this depends on your requirements, with NSURLRequest and NSURLConnection you can do everything, in fact AFNetworking us built on top of NSURLConnection. But how I tell you before, AFNetworking has my upvote.

    EDIT post iOS7

    If you are targeting iOS7 you should take a look to NSURLSession, check the official documentation, and this tutorial.

    EDIT for Swift

    Take a look to the Alamofire project for an implementation done in Swift, it is also created by mattt (the main author of AFNetworking).

    0 讨论(0)
  • 2021-02-01 04:13

    Native (NSURLSession) vs AFNetworking or any other library.

    I would recommend you to use NSURLSession because it gives you a lot of customization on app end. Recently I was working on a project, I have to use multipart form data some where in the app. I have to provide my request body to the backend guy, I did use AfNetworking logger to print my body but it did not help me. so I did move to cocoa native library and got my solution.

    so I would suggest you to use iOS native networking because it gives you a lot of customization but if you would need less code then you can use any 3rd party library.

    0 讨论(0)
  • 2021-02-01 04:19

    The asihttprequest is outdated library that doesn't support now for development. Do not use it.

    the NSURLRequest is default iOS (cocoa) class to use. I recommend it for very little usage because you will need to write lots of code to handle connection responses. On top of it are build all http libraries.

    The AFNetwoking is standart now for http, imho. It uses blocks for callbacks, it supports different types of data json, xml etc. it is well designed and can be easily subclassed. it is best.

    0 讨论(0)
提交回复
热议问题